1.1.0 • Published 2 years ago

@apie/responses v1.1.0

Weekly downloads
-
License
MIT
Repository
github
Last release
2 years 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.1.0

2 years ago

1.0.2

2 years ago

1.0.1

2 years ago

1.0.0

2 years ago