-
Notifications
You must be signed in to change notification settings - Fork 1.3k
/
http_verbs.js
56 lines (50 loc) · 1.82 KB
/
http_verbs.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
import http from "k6/http";
import { check, group } from "k6";
/*
* k6 supports all standard HTTP verbs/methods:
* CONNECT, DELETE, GET, HEAD, OPTIONS, PATCH, POST, PUT and TRACE.
*
* Below are examples showing how to use the most common of these.
*/
export default function() {
// GET request
group("GET", function() {
let res = http.get("http://httpbin.org/get?verb=get");
check(res, {
"status is 200": (r) => r.status === 200,
"is verb correct": (r) => r.json().args.verb === "get",
});
});
// POST request
group("POST", function() {
let res = http.post("http://httpbin.org/post", { verb: "post" });
check(res, {
"status is 200": (r) => r.status === 200,
"is verb correct": (r) => r.json().form.verb === "post",
});
});
// PUT request
group("PUT", function() {
let res = http.put("http://httpbin.org/put", JSON.stringify({ verb: "put" }), { headers: { "Content-Type": "application/json" }});
check(res, {
"status is 200": (r) => r.status === 200,
"is verb correct": (r) => r.json().json.verb === "put",
});
});
// PATCH request
group("PATCH", function() {
let res = http.patch("http://httpbin.org/patch", JSON.stringify({ verb: "patch" }), { headers: { "Content-Type": "application/json" }});
check(res, {
"status is 200": (r) => r.status === 200,
"is verb correct": (r) => r.json().json.verb === "patch",
});
});
// DELETE request
group("DELETE", function() {
let res = http.del("http://httpbin.org/delete?verb=delete");
check(res, {
"status is 200": (r) => r.status === 200,
"is verb correct": (r) => r.json().args.verb === "delete",
});
});
}