Package Exports
- httpsnippet-client-api
- httpsnippet-client-api/dist/index.js
This package does not declare an exports field, so the exports above have been automatically detected and optimized by JSPM instead. If any package subpath is missing, it is recommended to post an issue to the original package (httpsnippet-client-api) to support the "exports" field. If that is not possible, create a JSPM override to customize the exports field for this package.
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));