@apie/responses
TypeScript icon, indicating that this package has built-in type declarations

1.1.0 • Public • Published

@apie/responses NPM Package

What is @apie and @apie/responses?

An eco-system for infrastructure around REST API. It's worth noting that it is designed so that it can be used in all applications besides a REST API.

@apie/responses provides typed HTTP responses such as 200: OK.

Look at ./src/types to see "supported" HTTP statuses.

Examples

getBody

When working with a response, you can directly get the body via getBody.

It's worth noting, it doesn't work if this response is sent to ex. a frontend.\n Each responses stores response._body which is the RAW version of its content.

import { OK, getBody } from '@apie/responses'

const response = OK({ value: 123 })
getBody(response) // => { value: 123 }

isResponse

You can check if you have a response:

import { OK, isResponse } from '@apie/responses'

const response = OK({ value: 123 })
if(isResponse(response)) {
	// ...
}

The reason we do this, is because response instance Response will simplify the type to APIResponse which is generic for the responses of @apie/responses.

Readme

Keywords

Package Sidebar

Install

npm i @apie/responses

Weekly Downloads

63

Version

1.1.0

License

MIT

Unpacked Size

67.3 kB

Total Files

10

Last publish

Collaborators

  • refzlund