This repository has been archived by the owner on Dec 30, 2019. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathapi.conf
110 lines (85 loc) · 2.82 KB
/
api.conf
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
108
109
110
# for PEG.js
# Define new data model with name Error
model Error {
prop Number code = 400; # default value. If set to `$status` variable will be resolved from state
prop String error;
prop String docs?; # not required property. If provided `false`, `undefined` or `null` was not rendered
}
model User {
prop Number id?;
prop String login;
prop String email;
prop String password?;
prop Boolean admin? = false;
# What validates when request is coming
request {
required [email, login]; # must be one of that fields
required password;
}
# What validates before response
response {
required id;
}
}
model Admin {
extends User;
prop Boolean admin! = true;
prop Number[] roles;
}
model Tag {
prop String tag;
}
model Post {
prop Number id;
prop String title;
prop String content;
prop Number author?;
prop Date created?;
prop Date modificated?;
prop Tag[] tags?; # array of custom models
}
model Comment {
prop Number id;
prop String content;
prop Number author;
prop Date created;
}
# Define API v0
api 0 {
version path; # You can specify path for version: `version path /first.version`
# if version is `path` version will search at the end of host
# if version is `header`, version will search in header, example `version header Accept "application/your.app.v0"`
# If version is `none`, version not use. And that loaded if any version not loaded.
# Default `version path /v$version`
mediaType application/json application/xml; # first is used by default if another not set
# base get, post, put, patch, delete
# routes must starts with "/"
post /register to register; # resolve to action "register" of controller "index"
put /recover to recover; # resolve to action "recover" of controller "index".
# if patch not specified, was created alias to put
delete /session/:token to logout@session; # resolve to action "logout" of "session" controller with `token` param
# What model use on route
post /login to user use User; # resolve to "user" action with model
# define one resource
scope /back {
# scope not create route
post / to new; # resolve to "new" action of default controller ("index")
}
# Set controller for scope
# Does scope need `use Model`?
scope /whishlist to use/whishlist {
get / to list;
post / to add;
put /:id to update;
delete /:id to remove; # resolve to action `remove` at `use/whishlist` controller
}
}
# Define API v1
api 1 {
# will search header `X-API-Version: net.lestad.app.v1` for v1
version header X-API-Version "net.lestad.app.v$version";
# scheme was inherited
mediaType application/json; # use only json. JSON default for Olly
controller page; # set default controller to defined API
get /about to about; # resolve to action "about" of controller "page"
}