Skip to content

Repository files navigation

Ombi

Description

Ombi means "request" in Swahili.

Lightweight HTTP request wrapper built on top of got with normalised responses and managed error handling.

Installation

npm install @webinmove/ombi

Usage

importRequestfrom'@webinmove/ombi';constrequest=newRequest('https://api.example.com');// GETconstresponse=awaitrequest.call('GET','users/1');// POST with a bodyconstcreated=awaitrequest.call('POST','users',{body: {name: 'Alice'}});// GET with query string paramsconstlist=awaitrequest.call('GET','users',{qs: {page: 1,limit: 20}});// Custom headersconstsecured=awaitrequest.call('GET','protected',{},{Authorization: 'Bearer <token>'});

API

new Request(endpoint)

ParameterTypeDescription
endpointstringBase URL for all requests

request.call(method, path, params?, headers?, parentScope?, responseType?)

ParameterTypeDefaultDescription
methodstringnoneHTTP method (GET, POST, PUT, ...)
pathstringnonePath appended to the base endpoint
paramsobject{}body (sent as JSON for POST/PUT) and/or qs (query string)
headersobject{}Additional request headers
parentScopestring''Scope label forwarded to ManagedError on HTTP failures
responseTypestring | null'json'got response type; pass null to leave it unset

Returns a Promise that resolves to:

{ok: boolean,statusCode: number,statusMessage: string,body: unknown,headers: object}

HTTP errors (4xx / 5xx) are caught and re-thrown as a ManagedError (from @webinmove/kosa). All other errors are re-thrown as-is.

License

ISC

About

Lightweight HTTP request wrapper built on top of got with normalised responses and managed error handling.

Resources

Stars

0 stars

Watchers

0 watching

Forks

Releases

Packages

Contributors

Languages