-
Notifications
You must be signed in to change notification settings - Fork 0
/
demo.mjs
84 lines (80 loc) · 1.81 KB
/
demo.mjs
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
import Rests from './lib/index.js';
const API = Rests({
$options: {
base: 'https://postman-echo.com'
},
empty:{
help: 'Default get without params',
path: '/get'
},
user:{
help: 'The user endpoints',
login:{
help: 'User login request',
path: '/post',
method: 'POST',
params:{
username:{
required: true,
type: "string",
help: "A valid username is required",
validate: /\w+/
},
password: {
required: true,
help: "A valid password is required",
type: "string",
format: (password) => {
if(password.length < 8){
throw new Error("The password must be at least 8 characters.");
}
return password;
}
}
}
},
profile: {
help: 'Logged in user',
$options:{
params:{
//Set authentication parameters for all requests in this category
authorization: {
name: 'X-Auth',
location: 'headers',
required: true,
help: "The user authorization is required.",
validate: /^token/
}
}
},
info: {
help: 'User info',
path: '/headers'
},
about:{
me:{
help: 'User about',
path: '/headers'
}
},
update: {
help: 'User update profile.',
method: 'POST',
path: '/status/403',
enctype: 'form',
params: {
username: {
required: true,
type: "string",
help: "A valid username is required",
validate: /\w+/
}
}
}
},
overview:{
path: '/get?o=1',
}
}
});
export default API;