Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 0 additions & 1 deletion packages/api/.eslintignore
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
.github/
coverage/
node_modules/
example.js
1 change: 0 additions & 1 deletion packages/api/.npmignore
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
__tests__/
.github/
coverage/
.eslint*
.gitignore
Expand Down
1 change: 0 additions & 1 deletion packages/api/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,6 @@
"lint": "eslint .",
"pretest": "npm run lint && npm run prettier",
"prettier": "prettier --list-different --write \"./**/**.js\"",
"release": "conventional-changelog -i CHANGELOG.md -s",
"test": "jest --coverage"
},
"repository": {
Expand Down
3 changes: 3 additions & 0 deletions packages/httpsnippet-client-api/.eslintignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
__tests__/__fixtures__/
coverage/
node_modules/
4 changes: 4 additions & 0 deletions packages/httpsnippet-client-api/.eslintrc
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
{
"extends": "@readme/eslint-config",
"root": true
}
2 changes: 2 additions & 0 deletions packages/httpsnippet-client-api/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
coverage/
node_modules/
5 changes: 5 additions & 0 deletions packages/httpsnippet-client-api/.npmignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
__tests__/
coverage/
.eslint*
.gitignore
.prettier*
2 changes: 2 additions & 0 deletions packages/httpsnippet-client-api/.prettierignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
__tests__/__fixtures__/
coverage/
21 changes: 21 additions & 0 deletions packages/httpsnippet-client-api/HTTPSNIPPET-LICENSE
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
The MIT License (MIT)

Copyright (c) 2015 Mashape (https://www.mashape.com)

Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:

The above copyright notice and this permission notice shall be included in all
copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
SOFTWARE.
18 changes: 18 additions & 0 deletions packages/httpsnippet-client-api/LICENSE
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
Copyright © 2020 ReadMe

Permission is hereby granted, free of charge, to any person obtaining a copy of
this software and associated documentation files (the “Software”), to deal in
the Software without restriction, including without limitation the rights to
use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of
the Software, and to permit persons to whom the Software is furnished to do so,
subject to the following conditions:

The above copyright notice and this permission notice shall be included in all
copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED “AS IS”, WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS
FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR
COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER
IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, OUT OF OR IN CONNECTION WITH THE
SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
32 changes: 32 additions & 0 deletions packages/httpsnippet-client-api/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
# httpsnippet-client-api

An HTTP Snippet client for generating snippets for the [api](https://npm.im/api) module.

[![npm](https://img.shields.io/npm/v/httpsnippet-client-api)](https://npm.im/api) [![Build](https://github.com/readmeio/api/workflows/CI/badge.svg)](https://github.com/readmeio/api)

[![](https://d3vv6lp55qjaqc.cloudfront.net/items/1M3C3j0I0s0j3T362344/Untitled-2.png)](https://readme.io)


## Installation

```sh
npm install --save httpsnippet-client-api
```

> ⚠️ Please note that this package is currently only compatile with the [ReadMe fork of httpsnippet](https://github.com/readmeio/httpsnippet/). Once PR [#165](https://github.com/Kong/httpsnippet/pull/165) is accepted into `httpsnippet` to pull in the new plugin architecture we've proposed, this package will function with the mainline package.

## Usage

```js
const httpsnippet = require('httpsnippet');
const client = require('httpsnippet-client-api');

HTTPSnippet.addTargetClient('node', client);

const snippet = new HTTPSnippet(harObject);
console.log(
snippet.convert('node', 'api', {
apiDefinitionPath: 'https://example.com/openapi.json'
})
);
```
3 changes: 3 additions & 0 deletions packages/httpsnippet-client-api/__tests__/.eslintrc
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
{
"extends": "@readme/eslint-config/testing"
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
const sdk = require('api')('https://example.com/openapi.json');

sdk.post('/har', {foo: 'bar', hello: 'world'})
.then(res => res.json())
.then(res => {
console.log(res);
});
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
const sdk = require('api')('https://example.com/openapi.json');

sdk.post('/har', {
number: 1,
string: 'f"oo',
arr: [1, 2, 3],
nested: {a: 'b'},
arr_mix: [1, 'a', {arr_mix_nested: {}}],
boolean: false
})
.then(res => res.json())
.then(res => {
console.log(res);
});
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
const sdk = require('api')('https://example.com/openapi.json');

sdk.post('/har', {foo: 'bar'}, {foo: ['bar', 'baz'], baz: 'abc', key: 'value', accept: 'application/json'})
.then(res => res.json())
.then(res => {
console.log(res);
});
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
const sdk = require('api')('https://example.com/openapi.json');

sdk.get('/har', {accept: 'application/json', 'x-foo': 'Bar'})
.then(res => res.json())
.then(res => {
console.log(res);
});
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
const sdk = require('api')('https://example.com/openapi.json');

sdk.get('/har')
.then(res => res.json())
.then(res => {
console.log(res);
});
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
const sdk = require('api')('https://example.com/openapi.json');

sdk.post('/har', {foo: 'bar'})
.then(res => res.json())
.then(res => {
console.log(res);
});
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
const sdk = require('api')('https://example.com/openapi.json');

sdk.post('/har', {foo: null})
.then(res => res.json())
.then(res => {
console.log(res);
});
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
const sdk = require('api')('https://example.com/openapi.json');

sdk.post('/har', {
foo: {
value: 'Hello World',
options: {filename: 'hello.txt', contentType: 'text/plain'}
}
}, {'content-type': 'multipart/form-data; boundary=---011000010111000001101001'})
.then(res => res.json())
.then(res => {
console.log(res);
});
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
const fs = require("fs");
const sdk = require('api')('https://example.com/openapi.json');

sdk.post('/har', {
foo: {
value: 'fs.createReadStream("test/fixtures/files/hello.txt")',
options: {filename: 'test/fixtures/files/hello.txt', contentType: 'text/plain'}
}
}, {'content-type': 'multipart/form-data; boundary=---011000010111000001101001'})
.then(res => res.json())
.then(res => {
console.log(res);
});
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
const sdk = require('api')('https://example.com/openapi.json');

sdk.post('/har', {foo: 'bar'}, {'content-type': 'multipart/form-data; boundary=---011000010111000001101001'})
.then(res => res.json())
.then(res => {
console.log(res);
});
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
const sdk = require('api')('https://example.com/openapi.json');

sdk.get('/har', {foo: ['bar', 'baz'], baz: 'abc', key: 'value'})
.then(res => res.json())
.then(res => {
console.log(res);
});
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
const sdk = require('api')('https://example.com/openapi.json');

sdk.get('/har')
.then(res => res.json())
.then(res => {
console.log(res);
});
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
const sdk = require('api')('https://example.com/openapi.json');

sdk.post('/har', 'Hello World')
.then(res => res.json())
.then(res => {
console.log(res);
});
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
{
"method": "POST",
"url": "http://mockbin.com/har",
"headers": [
{
"name": "content-type",
"value": "application/x-www-form-urlencoded"
}
],
"postData": {
"mimeType": "application/x-www-form-urlencoded",
"params": [
{
"name": "foo",
"value": "bar"
},
{
"name": "hello",
"value": "world"
}
]
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
{
"method": "POST",
"url": "http://mockbin.com/har",
"headers": [
{
"name": "content-type",
"value": "application/json"
}
],
"postData": {
"mimeType": "application/json",
"text": "{\"number\":1,\"string\":\"f\\\"oo\",\"arr\":[1,2,3],\"nested\":{\"a\":\"b\"},\"arr_mix\":[1,\"a\",{\"arr_mix_nested\":{}}],\"boolean\":false}"
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
{
"method": "POST",
"url": "http://mockbin.com/har",
"cookies": [
{
"name": "foo",
"value": "bar"
},
{
"name": "bar",
"value": "baz"
}
]
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
{
"method": "PROPFIND",
"url": "http://mockbin.com/har"
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,48 @@
{
"method": "POST",
"url": "http://mockbin.com/har?key=value",
"httpVersion": "HTTP/1.1",
"queryString": [
{
"name": "foo",
"value": "bar"
},
{
"name": "foo",
"value": "baz"
},
{
"name": "baz",
"value": "abc"
}
],
"headers": [
{
"name": "accept",
"value": "application/json"
},
{
"name": "content-type",
"value": "application/x-www-form-urlencoded"
}
],
"cookies": [
{
"name": "foo",
"value": "bar"
},
{
"name": "bar",
"value": "baz"
}
],
"postData": {
"mimeType": "application/x-www-form-urlencoded",
"params": [
{
"name": "foo",
"value": "bar"
}
]
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
{
"method": "GET",
"url": "http://mockbin.com/har",
"headers": [
{
"name": "accept",
"value": "application/json"
},
{
"name": "x-foo",
"value": "Bar"
}
]
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
{
"method": "GET",
"url": "https://mockbin.com/har"
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
{
"url": "http://mockbin.com/har",
"method": "POST",
"headers": [{
"name": "content-type",
"value": "application/json"
}],
"postData": {
"text": "{\n \"foo\": \"bar\"\n}",
"mimeType": "application/json"
}
}
Loading