GithubHelp home page GithubHelp logo

reqsink's Introduction

reqsink

A lightweight HTTP request sink inspired by the original requestbin, implemented in Rust as a compact, single-file binary for easy deployment.

Getting started

It's as simple as:

$ docker run -p 8000:8000 atomic77/reqsink:latest
Total 1 templates loaded:
"admin.html"
Binding to interface "0.0.0.0:8000"

Then send a request:

curl -X POST -H "Content-Type: application/json" \
  -d '{"hello": "world", "foo": "bar"}' \
  localhost:8000/post/some/json

The /admin route provides a simple GUI showing the current tracked requests. Syntax highlighting and pretty-printing is available for formats such as JSON, using the embedded highlight.js:

Admin page

If you don't want to use docker, a static binary is available for linux_amd64. Other platforms should work fine, so far I've tested armv7.

User-defined templates

The default response to any request to is a terse "OK". If you want to customize the response for a given route, reqsink supports the use of Tera (jinja-style) templates.

User templates are rendered with access to a StoredRequest. See main.rs for the struct definition and the fields available in the template. eg. for the custom robots.txt response in the examples directory, the template is defined as:

# Hello, IP {{ request.ip_addr }}. We've been expecting you.

# Group 1
User-agent: Googlebot
Disallow: /nogooglebot/

See the examples directory for a configuration and template for a user-defined route. Any .html file in templates-dir or its subfolders will be treated as a template.

To run with user-defined templates, you can use a command like the following:

reqsink --user-templates-dir examples --extra-routes ./examples/example-routes.json

Command line options

OPTIONS:
    -e, --extra-routes <extra-routes>
            A JSON file mapping the desired route -> template

    -i, --ip-address <ip-address>                    IP-address to bind to [default: 0.0.0.0]
    -p, --port <port>                                Port to bind to [default: 8000]
    -r, --req-limit <req-limit>
            Maximum number of requests to keep in memory [default: 1000]
    -s, --sqlite <sqlite>
            Filename of sqlite database to use for persistence (EXPERIMENTAL)
    -u, --user-templates-dir <user-templates-dir>
            User-defined templates directory. If you want to provide a custom response to a
            particular endpoint, you will need to also provide a JSON file mapping the template to
            the route

Limitations / TODO items

  • Make request store accessible from admin UI
  • Ability to export requests
  • User-defined templates cannot be used with the same route for more than one method (eg. /robots.txt can't have a different GET and POST response)

reqsink's People

Contributors

atomic77 avatar oylbin avatar

Stargazers

Arnaud Limbourg avatar  avatar Pieter Janssens avatar Stéphane avatar Raphael Campardou avatar Alex Ausch avatar Maciej Duda avatar

Watchers

 avatar

Forkers

oylbin

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.