Skip to main content

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

const { buildApiRequestString } = require("js-ts-kit");

Function

buildApiRequestString(method, url, headers, body)

Parameters

NameTypeDescription
methodstringmethod of request
urlstringentire url of request
headers{ [key: string]: string }header of request
bodystringbody of request

Returns

  • Type: string

  • Description: string to 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...