RequestTemplater is a class for generating HTTP request examples based on templates for different programming languages.
npm install request-templater





RequestTemplater is a class for generating HTTP request examples based on templates for different programming languages.
``npm install request-templater`
`js
import RequestTemplater from 'request-templater';
const requestTemplater = new RequestTemplater();
`
Then you can set the base URL and other request parameters:
`js`
requestTemplater.baseUrl('https://example.com/api')
.method('GET')
.url('users/123')
.params([
{ in: 'query', name: 'page', value: '1' },
{ in: 'query', name: 'limit', value: '10' },
{ in: 'headers', name: 'Authorization', value: 'Bearer xxxxxxxxxxxx' }
]);
After that, you can generate a request example for the desired language:
`js`
const code = requestTemplater.lang('javascript').library('axios').generate();
console.log(code);
In this example, code in the JavaScript language will be generated using the Axios library.
Need add style, for example: ``
| Language | Libraries |
|-------------|--------------------------------------|
| Swift | URLSession, Alamofire |
| Shell | wget, httpie, curl |
| Scala | scalaj-http, http4s, akka |
| Rust | surf, reqwest, hyper |
| Ruby | RestClient, http |
| Python | requests, http |
| PowerShell | WebRequest, RestMethod |
| PHP | http2, http1, Guzzle, curl |
| Perl | UserAgent, Tiny, Request |
| OCaml | httpaf, cohttp_lwt |
| Objective-C | NSURLSession, AFNetworking |
| Lua | httpclient, http, curl |
| Kotlin | OkHttp3, Java, Fuel |
| JavaScript | jQuery, Fetch, Axios, XMLHttpRequest |
| Java | Unirest, OkHttp, NetHttp, AsyncHttp |
| HTTP | RFC7230 |
| Go | http, fasthttp |
| Dart | http_client, http, Dio |
| C# | RestSharp, HttpClient |
| C++ | iostream, curl, Arduino |
| Clojure | Ring-Client, clj-http |
| C | ghttp, curl |
| Brainfuck | Brainfuck |
| R | RCurl, httr |
Install the request-templater package globally using npm:
`bash`
npm install -g request-templater
To use Request Templater, run the request-templater command in your terminal, specifying the necessary parameters. For example:
request-templater --url https://api.example.com/users --method POST --lang bash --library curl --params '[{in: "query", name: "param", value: 1}]'
In this example, we're specifying the URL, request method, programming language (javascript), and request parameters in JSON format.
Request Templater supports the following parameters:
-u, --url : The URL of the request (required)-m, --method : The HTTP method (defaults to GET)-l, --language : The programming language to generate code in (defaults to javascript)-t, --mimeType : The MIME type of the request (optional)-p, --params : The request parameters (optional)-b, --baseUrl : The base URL for the request (optional)-r, --library : The HTTP library to use for making the request (defaults to xhr)
To get help on the command line parameters, run the request-templater -h command:
`bash``
request-templater -h