Skip to content

Commit f061020

Browse files
committed
Update README.md
1 parent 6310766 commit f061020

1 file changed

Lines changed: 81 additions & 49 deletions

File tree

‎README.md‎

Lines changed: 81 additions & 49 deletions
Original file line numberDiff line numberDiff line change
@@ -39,60 +39,24 @@ Options:
3939
-n, --output-name <name> output file name
4040
```
4141

42-
#### Example
43-
44-
process single file (assumes [HAR Request Object](http://www.softwareishard.com/blog/har-12-spec/#request) Format):
45-
46-
###### EXAMPLE: *my-api-endpoint.json*
47-
48-
```json
49-
{
50-
"method": "POST",
51-
"url": "http://mockbin.com/request",
52-
"httpVersion": "HTTP/1.1",
53-
"queryString": [
54-
{ "name": "foo", "value": "bar" },
55-
{ "name": "foo", "value": "baz" },
56-
{ "name": "baz", "value": "abc" }
57-
],
58-
"headers": [
59-
{ "name": "Accept", "value": "text/plain" },
60-
{ "name": "Content-Type", "value": "application/json" },
61-
{ "name": "X-Foo-Bar", "value": "Baz" }
62-
],
63-
"cookies": [
64-
{ "name": "foo", "value": "bar" },
65-
{ "name": "bar", "value": "baz" }
66-
],
67-
"postData": {
68-
"mimeType": "application/json",
69-
"text": "{\"foo\": \"bar\"}"
70-
}
71-
}
72-
```
42+
###### Example
43+
44+
process single file: [`example.json`](test/fixtures/requests/full.json) from [HAR Request Object](http://www.softwareishard.com/blog/har-12-spec/#request) format:
7345

7446
```shell
75-
httpsnippet my-api-endpoint.json --target php --output ./snippets
47+
httpsnippet example.json --target node --client unirest --output ./snippets
7648
```
7749

7850
```shell
7951
$ tree snippets
8052
snippets/
81-
└── my-api-endpoint.php
53+
└── example.js
8254
```
8355

8456
process multiple files:
8557

8658
```shell
87-
httpsnippet /*.json --target node --client native --output ./snippets
88-
```
89-
90-
```shell
91-
$ tree sources/
92-
sources/
93-
├── endpoint-1.json
94-
├── endpoint-2.json
95-
└── endpoint-3.json
59+
httpsnippet ./*.json --target node --client request --output ./snippets
9660
```
9761

9862
```shell
@@ -105,24 +69,92 @@ snippets/
10569

10670
## API
10771

72+
### HTTPSnippet(source)
73+
74+
#### source
75+
76+
*Required*
77+
Type: `object`
78+
79+
Name of [conversion target](src/targets)
80+
81+
```js
82+
var httpsnippet = require('httpsnippet');
83+
84+
var snippet = new HTTPSnippet({
85+
method: 'GET',
86+
url: 'http://mockbin.com/request'
87+
});
88+
```
89+
90+
### convert(target [, options])
91+
92+
#### target
93+
94+
*Required*
95+
Type: `string`
96+
97+
Name of [conversion target](src/targets)
98+
99+
#### options
100+
101+
Type: `object`
102+
103+
Target options, *see [wiki](wiki) for details*
104+
108105
```js
109106
var httpsnippet = require('httpsnippet');
110107

111-
var snippet = new httpsnippet({
108+
var snippet = new HTTPSnippet({
112109
method: 'GET',
113110
url: 'http://mockbin.com/request'
114111
});
115112

116-
// generate cURL output
117-
console.log(snippet.convert('curl', {
113+
// generate Node.js: Native output
114+
console.log(snippet.convert('node'));
115+
116+
// generate Node.js: Native output, indent with tabs
117+
console.log(snippet.convert('node', {
118118
indent: '\t';
119119
}));
120+
```
120121

121-
// generate Node.js output
122-
console.log(snippet.convert('node'));
122+
### convert(target [, client, options])
123+
124+
#### target
125+
126+
*Required*
127+
Type: `string`
128+
129+
Name of [conversion target](src/targets)
130+
131+
#### client
132+
133+
Type: `string`
134+
135+
Name of conversion target [client library](src/targets)
136+
137+
#### options
138+
139+
Type: `object`
140+
141+
Target options, *see [wiki](wiki) for details*
142+
143+
```js
144+
var httpsnippet = require('httpsnippet');
145+
146+
var snippet = new HTTPSnippet({
147+
method: 'GET',
148+
url: 'http://mockbin.com/request'
149+
});
150+
151+
// generate Shell: cURL output
152+
console.log(snippet.convert('shell', 'curl', {
153+
indent: '\t';
154+
}));
123155

124-
// generate PHP output
125-
console.log(snippet.convert('php', 'curl'));
156+
// generate Node.js: Unirest output
157+
console.log(snippet.convert('node', 'unirest'));
126158
```
127159

128160
## Documentation

0 commit comments

Comments
 (0)