-
Notifications
You must be signed in to change notification settings - Fork 0
/
demos.post.js
107 lines (92 loc) · 3.06 KB
/
demos.post.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
/**
*
* Package:
* Author: Ganesh B
* Description:
* Install: npm i request-apis --save
* Github: https://github.com/ganeshkbhat/apis-request
* npmjs Link: https://www.npmjs.com/package/request-apis
* File: test-.js
* Test for File: index.js
* File Description:
*
*/
'use strict';
// https://petstore.swagger.io/
// https://petstore.swagger.io/v2/pet
const req = require("../index.js");
let data = {
"id": 0,
"category": {
"id": 0,
"name": "string"
},
"name": "doggiestore",
"photoUrls": [
"string"
],
"tags": [
{
"id": 0,
"name": "string"
}
],
"status": "available"
}
let r = req._postRequest({ hostname: "petstore.swagger.io", port: 443, path: "/v2/pet", method: "POST", headers: { "content-type": "application/json", "accept": "application/json" } }, data, "https");
r.then(rs => console.log(JSON.stringify(rs)))
data.name = "newstore";
let rc = req._postRequest({ hostname: "petstore.swagger.io", port: 443, path: "/v2/pet", method: "POST", headers: { "content-type": "application/json", "accept": "application/json" } }, data, "https");
rc.then(rs => console.log(JSON.stringify(rs)))
// // // Example Response:
// // //
// // {
// // "headers": {
// // "date": "Mon, 02 Jan 2023 02:23:55 GMT", "content-type": "application/json", "transfer-encoding": "chunked", "connection": "close", "access-control-allow-origin": "*", "access-control-allow-methods": "GET, POST, DELETE, PUT", "access-control-allow-headers": "Content-Type, api_key, Authorization", "server": "Jetty(9.2.9.v20150224)"
// // }, "body": {
// // "id": 9223372036854244000, "category": { "id": 0, "name": "string" }, "name": "doggiestore", "photoUrls": ["string"], "tags": [{ "id": 0, "name": "string" }], "status": "available"
// // }
// // }
// // //
let dataXML= `<?xml version="1.0" encoding="UTF-8"?>
<Pet>
<id>0</id>
<Category>
<id>0</id>
<name>string</name>
</Category>
<name>doggie</name>
<photoUrls>
<photoUrl>string</photoUrl>
</photoUrls>
<tags>
<Tag>
<id>0</id>
<name>string</name>
</Tag>
</tags>
<status>available</status>
</Pet>`
let rxml = req._postRequest({ hostname: "petstore.swagger.io", port: 443, path: "/v2/pet", method: "POST", headers: { "content-type": "application/xml", "accept": "application/xml" } }, dataXML, "https");
rxml.then(rs => console.log(JSON.stringify(rs)))
dataXML = `<?xml version="1.0" encoding="UTF-8"?>
<Pet>
<id>0</id>
<Category>
<id>0</id>
<name>string</name>
</Category>
<name>newstore</name>
<photoUrls>
<photoUrl>string</photoUrl>
</photoUrls>
<tags>
<Tag>
<id>0</id>
<name>string</name>
</Tag>
</tags>
<status>available</status>
</Pet>`
let rcxml = req._postRequest({ hostname: "petstore.swagger.io", port: 443, path: "/v2/pet", method: "POST", headers: { "content-type": "application/xml", "accept": "application/xml" } }, dataXML, "https");
rcxml.then(rs => console.log(JSON.stringify(rs)))