> Inspired when developing an internal API client in my company [Yamsafer](https://github.com/Yamsafer) :heart:, and by the design of the [Cloudflare NodeJS client](https://github.com/cloudflare/node-cloudflare) :heart:.
This library aims to simplify the creation of HTTP API clients by providing a declarative abstraction of HTTP requests.
Instead of worrying about how to consume some HTTP API, we should focus on the buisness logic behind this API call, so instead of worrying about whether the HTTP request library uses promises, or callbacks, or how the response object is formated, you simply declare what you want, and move on with your life.
So instead of having the focus be centered around how you make the request like the following,
The above boilerplate where you worry about whether you're using `request` or `request-promise` or whatnot, and you worry about how to resolve your response and what it looks like, get completely abstracted and unified into,
And you gain the consistent response structure (placed inside a promise). This can be extended even further into building entire clients for you APIs!
It also adds support for standardized validation for request arguments, query strings, and payload (provided using [Joi](https://github.com/hapijs/joi) :heart:)
<!-- We separate installation of `got` and `portal` to prepare for later support of multiple internal clients, mainly to support browsers using `ky` without introducing breaking changes. -->
A function (representing a MethodFactory), used to generate client routes. It takes for an input a [MethodSpec](######methodspec) and returns a function representing the API call.
###### MethodSpec
An object with the following attributes
**`path`** (required) `string`
The URL path for the route, it should be a relateive path given the [baseUrl](#####baseurl) defined when initiating the portal client.
**`method`** (optional) `string`
The method for the HTTP call, defaults to `GET`.
**`params`** (optional) [`ValdiationSpec`]()
An optional validation specification for the path arguments in of the route.
**`body`** (optional) [`ValdiationSpec`]()
An optional validation specification for the payload arguments of the route.
**`queryString`** (optional) [`ValdiationSpec`]()
An optional validation specification for the query string arguments in of the route.
**`contentType`** (optional) `string`
The Content-Type header value of the request, defaults to `application/json`.
**`accept`** (optional) `string`
The Accept header value of the request, defaults to `application/json`.
**`headers`** (optional) `OutgoingHttpHeaders`
Additional headers to always be added to requests to the given route, defaults to `{}`.
A function that takes any number of arguments and performs the HTTP request.
The only special argument is the last one, which can be an object hodling any request options that can be used by the underlying client, as well as the payload (under the key `payload`) and query string (under the key `queryString`) objects if needed.
A function (representing a ResourceFactory), and can be used to generate client resources. A resource is a basic CRUD API for a given route, providing a default set of APIs for `list`, `get`, `edit`, `add`, and `delete`, those APIs correspond to the following HTTP calls,
- list -> `GET /some-uri`
- get -> `GET /some-uri/:id`
- edit -> `PUT /some-uri/:id { some payload to update the ID with }`
- add (aliased as set) `POST /some-uri { some payload to create a new reource with }`
- del (aliased as delete) `DELETE /some-uri/:id`
It takes a [`ResourceConfig`](######resourceconfig) object as input and returns a ResourceFactory function. When calling the ResourceFactory, the result is an object with the list of CRUD operations (and any additional ones defined in the resource config) as function defined on it.
The result from using the resource factory, is an object with the enabled default resource method, and any other extra ones as its keys, and each of those keys poiting to the `RouteFunction` used to execute the API call.
A JSON with string keys mapping to corresponding [MethodSpec](######methodspec). Each key will be added an added method defined by it's corresponding spec. Defaults to `{}`.
The underlying client instance used by the two previous factories. This is exposed only for transparncy but is not intended to be used ideally by anyone external.