Skip to content

webinmove/ombi

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

1 Commit
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

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

import Request from '@webinmove/ombi';

const request = new Request('https://api.example.com');

// GET
const response = await request.call('GET', 'users/1');

// POST with a body
const created = await request.call('POST', 'users', {
  body: { name: 'Alice' }
});

// GET with query string params
const list = await request.call('GET', 'users', {
  qs: { page: 1, limit: 20 }
});

// Custom headers
const secured = await request.call('GET', 'protected', {}, {
  Authorization: 'Bearer <token>'
});

API

new Request(endpoint)

Parameter Type Description
endpoint string Base URL for all requests

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

Parameter Type Default Description
method string none HTTP method (GET, POST, PUT, ...)
path string none Path appended to the base endpoint
params object {} body (sent as JSON for POST/PUT) and/or qs (query string)
headers object {} Additional request headers
parentScope string '' Scope label forwarded to ManagedError on HTTP failures
responseType string | 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

Watchers

Forks

Releases

No releases published

Packages

 
 
 

Contributors