1.3.3 • Published 7 months ago

request-templater v1.3.3

Weekly downloads
-
License
MIT
Repository
github
Last release
7 months ago

npm version npm downloads NPM license npm type definitions donate GitHub Repo stars

RequestTemplater

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

Example

Show

Installation

To install RequestTemplater, run the following command:

npm install request-templater

Usage

To get started with RequestTemplater, create an instance of the class:

import RequestTemplater from 'request-templater';

const requestTemplater = new RequestTemplater();

Then you can set the base URL and other request parameters:

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:

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.

Methods

baseUrl(value: string): RequestTemplater

Method for setting the base URL for requests.

method(value: 'GET'|'POST'|'PUT'|'DELETE'|'PATCH'|'HEAD'|'OPTIONS'): RequestTemplater

Method for setting the HTTP method for requests.

url(value: string): RequestTemplater

Method for setting the path for requests.

params(value: Array): RequestTemplater

Method for setting request parameters.

mimeType(value: "application/x-www-form-urlencoded"|"application/json"|'multipart/form-data'): RequestTemplater

Method for setting the MIME type for requests.

lang(value: string): RequestTemplater

Method for setting the programming language for which a request example will be generated.

library(value: string): RequestTemplater

Method for setting the library that will be used to send the request.

generate(): string

Method for generating a request example based on the specified parameters.

generateHighlight(): string

Method for generating a request example based on the specified parameters with highlight.js tags.

Need add style, for example: <link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/highlight.js/11.7.0/styles/tokyo-night-dark.min.css" integrity="sha512-dSQLLtgaq2iGigmy9xowRshaMzUHeiIUTvJW/SkUpb1J+ImXOPNGAI7ZC8V5/PiN/XN83B8uIk4qET7AMhdC5Q==" crossorigin="anonymous" referrerpolicy="no-referrer" />

config(): Object

Method for getting a list of available templates for generating request examples.

Language and Libraries

LanguageLibraries
SwiftURLSession, Alamofire
Shellwget, httpie, curl
Scalascalaj-http, http4s, akka
Rustsurf, reqwest, hyper
RubyRestClient, http
Pythonrequests, http
PowerShellWebRequest, RestMethod
PHPhttp2, http1, Guzzle, curl
PerlUserAgent, Tiny, Request
OCamlhttpaf, cohttp_lwt
Objective-CNSURLSession, AFNetworking
Luahttpclient, http, curl
KotlinOkHttp3, Java, Fuel
JavaScriptjQuery, Fetch, Axios, XMLHttpRequest
JavaUnirest, OkHttp, NetHttp, AsyncHttp
HTTPRFC7230
Gohttp, fasthttp
Darthttp_client, http, Dio
C#RestSharp, HttpClient
C++iostream, curl, Arduino
ClojureRing-Client, clj-http
Cghttp, curl
BrainfuckBrainfuck
RRCurl, httr

cli

Install the request-templater package globally using npm:

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 <url>: The URL of the request (required) -m, --method <method>: The HTTP method (defaults to GET) -l, --language <language>: The programming language to generate code in (defaults to javascript) -t, --mimeType <mimeType>: The MIME type of the request (optional) -p, --params <params>: The request parameters (optional) -b, --baseUrl <baseUrl>: The base URL for the request (optional) -r, --library <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:

request-templater -h
1.3.3

7 months ago

1.3.2

1 year ago

1.3.1

1 year ago

1.2.1

2 years ago

1.1.2

2 years ago

1.1.1

2 years ago

1.0.10

2 years ago

1.0.9

2 years ago

1.0.8

2 years ago

1.0.7

2 years ago

1.0.6

2 years ago

1.0.4

2 years ago

1.0.3

2 years ago

1.0.2

2 years ago

1.0.1

2 years ago

1.0.0

2 years ago