metro.api
metro.api
Returns an API object, which extends metro.client with the methods passed as the second parameter. E.g:
Functions must not be defined with the arrow syntax ((foo) => { … }). Otherwise the function won’t have access to this.post etc.
The first param is wrapped in a metro.client, e.g. metro.client('https://example.com'), so it can be any valid parameter for metro.client, including a metro client itself.
The metro.api() automatically adds the thrower and getdata middleware to the metro client.
metro.jsonApi
This creates a new API with the presumption that all API methods should send JSON as the body and parse the result again as JSON. It adds ‘Content-Type: application/json’ and ‘Accept: application/json’ headers, unless Content-Type or Accept headers are already present.
Any client methods that return a response, now return the parsed JSON instead, if JSON is returned.