Git Product home page Git Product logo

req's Introduction

req

req is an opinionated HTTP scripting language. It is designed for easily making HTTP requests, and working with their responses. Below is an example that calls out to the GitHub API and displays the user making the call,

$ cat gh.req
Stderr = open "/dev/stderr";

Endpoint = "https://api.github.com";
Token = env "GH_TOKEN";

if $Token == "" {
    writeln $Stderr "GH_TOKEN not set";
    exit 1;
}

Headers = (
    Authorization: "Bearer $(Token)",
);

Resp = GET "$(Endpoint)/user" $Headers -> send;

match $Resp.StatusCode {
    200 -> {
        User = decode json $Resp.Body;

        writeln _ "Hello $(User["login"])";
    }
    _   -> {
        writeln $Stderr "Unexpected response: $(Resp.Status)";
        exit 1;
    }
}
$ GH_TOKEN=1a2b3c4d5ef req gh.req

This language hopes to fill in a gap when it comes to writing scripts for working with an HTTP service. Typically, you have a choice between a shell script that utilizes cURL, or a programmaing language and any HTTP library that may come with it.

The cURL approach can work, for simple one off requests, but when you want to do something more with the response you're left with having to munge that data with jq, grep, sed, or awk (or all of the above). Using a programming language gives you more control, but can be more cumbersome as you have far many more knobs to turn.

req provides a middleground between the two. A limited syntax, with builtin commands for working with any data you want to send/received. For more details on how to start working with req, then refer to the documentation, or you can dive right in by looking over the examples.

req's People

Contributors

andrewpillar avatar floj avatar

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.