buildApiRequestString
Function that builds API request string that can be used to call API endpoints manually.
note
Function can be used in frontend and backend
Import
- ES5
- ES6
const { buildApiRequestString } = require("js-ts-kit");
import { buildApiRequestString } from "js-ts-kit";
Function
buildApiRequestString(method, url, headers, body)
Parameters
| Name | Type | Description |
|---|---|---|
method | string | method of request |
url | string | entire url of request |
headers | { [key: string]: string } | header of request |
body | string | body of request |
Returns
-
Type:
string -
Description:
stringto be used for calling API endpoints manually
Example
Live Editor
function Example() { const method = "POST"; const url = "http://localhost:8080"; const headers = { "Content-Type": "application/json", Authorization: `Bearer eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJzdWIiOiIxMjM0NTY3ODkwIiwiaWQiOjEsImlhdCI6MTUxNjIzOTAyMn0.qbkPu51ruczq9jWaoHR6jDbyU6q06QZoSVX98zboWvg`, }; const bodyString = JSON.stringify({ email: "email", password: "password" }); return <>{buildApiRequestString(method, url, headers, bodyString)}</>; }
Result
Loading...