httpsnippet-client-api
v6.1.3
Published
An HTTPSnippet client for generating snippets for the `api` module.
Downloads
5,713
Maintainers
Keywords
Readme
httpsnippet-client-api
An HTTPSnippet client for generating snippets for the api module.
Installation
npm install --save httpsnippet-client-api
Usage
import { HTTPSnippet, addTargetClient } from 'httpsnippet';
import client = require('httpsnippet-client-api');
addTargetClient('node', client);
const har = {
"log": {
"entries": [
{
"request": {
"cookies": [],
"httpVersion": "HTTP/1.1",
"method": "PUT",
"headers": [
{
"name": "X-API-KEY",
"value": "a5a220e"
}
],
"url": "https://httpbin.org/apiKey"
}
}
]
}
}
const snippet = new HTTPSnippet(har);
const code = snippet.convert('node', 'api', {
apiDefinitionUri: 'https://api.example.com/openapi.json'
apiDefinition: {
/* an OpenAPI definition object */
}
});
console.log(code);
Results in the following:
const sdk = require('api')('https://api.example.com/openapi.json');
sdk.auth('a5a220e');
sdk
.put('/apiKey')
.then(({ data }}) => console.log(data))
.catch(err => console.error(err));