1.0.2 • Published 1 year ago

@apie/responses v1.0.2

Weekly downloads
-
License
MIT
Repository
github
Last release
1 year ago

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.

1.0.2

1 year ago

1.0.1

1 year ago

1.0.0

1 year ago