1
1
// # API routes
2
2
var express = require ( 'express' ) ,
3
3
api = require ( '../api' ) ,
4
- apiRoutes ;
4
+ apiRoutes ,
5
+ resources ;
6
+
7
+ resources = {
8
+ posts : function ( router ) {
9
+ router . get ( '/posts' , api . http ( api . posts . browse ) ) ;
10
+ router . post ( '/posts' , api . http ( api . posts . add ) ) ;
11
+ router . get ( '/posts/:id' , api . http ( api . posts . read ) ) ;
12
+ router . get ( '/posts/slug/:slug' , api . http ( api . posts . read ) ) ;
13
+ router . put ( '/posts/:id' , api . http ( api . posts . edit ) ) ;
14
+ router . del ( '/posts/:id' , api . http ( api . posts . destroy ) ) ;
15
+ }
16
+ } ;
5
17
6
18
apiRoutes = function ( middleware ) {
7
19
var router = express . Router ( ) ;
20
+ // alias delete with del
21
+ router . del = router . delete ;
8
22
9
23
// ## Posts
10
- router . get ( '/ghost/api/v0.1/posts' , api . http ( api . posts . browse ) ) ;
11
- router . post ( '/ghost/api/v0.1/posts' , api . http ( api . posts . add ) ) ;
12
- router . get ( '/ghost/api/v0.1/posts/:id(\\d+)' , api . http ( api . posts . read ) ) ;
13
- router . get ( '/ghost/api/v0.1/posts/:slug([a-z-]+)' , api . http ( api . posts . read ) ) ;
14
- router . put ( '/ghost/api/v0.1/posts/:id' , api . http ( api . posts . edit ) ) ;
15
- router [ 'delete' ] ( '/ghost/api/v0.1/posts/:id' , api . http ( api . posts . destroy ) ) ;
24
+ router . get ( '/posts' , api . http ( api . posts . browse ) ) ;
25
+ router . post ( '/posts' , api . http ( api . posts . add ) ) ;
26
+ router . get ( '/posts/:id' , api . http ( api . posts . read ) ) ;
27
+ router . get ( '/posts/slug/:slug' , api . http ( api . posts . read ) ) ;
28
+ router . put ( '/posts/:id' , api . http ( api . posts . edit ) ) ;
29
+ router . del ( '/posts/:id' , api . http ( api . posts . destroy ) ) ;
30
+
16
31
// ## Settings
17
- router . get ( '/ghost/api/v0.1/settings/' , api . http ( api . settings . browse ) ) ;
18
- router . get ( '/ghost/api/v0.1/settings/:key/' , api . http ( api . settings . read ) ) ;
19
- router . put ( '/ghost/api/v0.1/settings/' , api . http ( api . settings . edit ) ) ;
32
+ router . get ( '/settings' , api . http ( api . settings . browse ) ) ;
33
+ router . get ( '/settings/:key' , api . http ( api . settings . read ) ) ;
34
+ router . put ( '/settings' , api . http ( api . settings . edit ) ) ;
35
+
20
36
// ## Users
21
- router . get ( '/ghost/api/v0.1/users/' , api . http ( api . users . browse ) ) ;
22
- router . get ( '/ghost/api/v0.1/users/:id/' , api . http ( api . users . read ) ) ;
23
- router . put ( '/ghost/api/v0.1/users/password/' , api . http ( api . users . changePassword ) ) ;
24
- router . put ( '/ghost/api/v0.1/users/:id/' , api . http ( api . users . edit ) ) ;
25
- router . post ( '/ghost/api/v0.1/users/' , api . http ( api . users . invite ) ) ;
26
- router [ 'delete' ] ( '/ghost/api/v0.1/users/:id/' , api . http ( api . users . destroy ) ) ;
37
+ router . get ( '/users' , api . http ( api . users . browse ) ) ;
38
+ router . get ( '/users/:id' , api . http ( api . users . read ) ) ;
39
+ router . get ( '/users/slug/:slug' , api . http ( api . users . read ) ) ;
40
+ router . get ( '/users/email/:email' , api . http ( api . users . read ) ) ;
41
+ router . put ( '/users/password' , api . http ( api . users . changePassword ) ) ;
42
+ router . put ( '/users/:id' , api . http ( api . users . edit ) ) ;
43
+ router . post ( '/users' , api . http ( api . users . invite ) ) ;
44
+ router . del ( '/users/:id' , api . http ( api . users . destroy ) ) ;
27
45
28
46
// ## Tags
29
- router . get ( '/ghost/api/v0.1/tags/' , api . http ( api . tags . browse ) ) ;
47
+ router . get ( '/tags' , api . http ( api . tags . browse ) ) ;
48
+
49
+ // ## Slugs
50
+ router . get ( '/slugs/:type/:name' , api . http ( api . slugs . generate ) ) ;
51
+
30
52
// ## Themes
31
- router . get ( '/ghost/api/v0.1/themes/' , api . http ( api . themes . browse ) ) ;
32
- router . put ( '/ghost/api/v0.1/themes/:name' , api . http ( api . themes . edit ) ) ;
53
+ router . get ( '/themes' , api . http ( api . themes . browse ) ) ;
54
+ router . put ( '/themes/:name' , api . http ( api . themes . edit ) ) ;
55
+
33
56
// ## Notifications
34
- router . get ( '/ghost/api/v0.1/notifications/' , api . http ( api . notifications . browse ) ) ;
35
- router . post ( '/ghost/api/v0.1/notifications/' , api . http ( api . notifications . add ) ) ;
36
- router [ 'delete' ] ( '/ghost/api/v0.1/notifications/:id' , api . http ( api . notifications . destroy ) ) ;
57
+ router . get ( '/notifications' , api . http ( api . notifications . browse ) ) ;
58
+ router . post ( '/notifications' , api . http ( api . notifications . add ) ) ;
59
+ router . del ( '/notifications/:id' , api . http ( api . notifications . destroy ) ) ;
60
+
37
61
// ## DB
38
- router . get ( '/ghost/api/v0.1/db/' , api . http ( api . db . exportContent ) ) ;
39
- router . post ( '/ghost/api/v0.1/db/' , middleware . busboy , api . http ( api . db . importContent ) ) ;
40
- router [ 'delete' ] ( '/ghost/api/v0.1/db/' , api . http ( api . db . deleteAllContent ) ) ;
62
+ router . get ( '/db' , api . http ( api . db . exportContent ) ) ;
63
+ router . post ( '/db' , middleware . busboy , api . http ( api . db . importContent ) ) ;
64
+ router . del ( '/db' , api . http ( api . db . deleteAllContent ) ) ;
65
+
41
66
// ## Mail
42
- router . post ( '/ghost/api/v0.1/ mail' , api . http ( api . mail . send ) ) ;
43
- router . post ( '/ghost/api/v0.1/ mail/test' , function ( req , res ) {
67
+ router . post ( '/mail' , api . http ( api . mail . send ) ) ;
68
+ router . post ( '/mail/test' , function ( req , res ) {
44
69
api . settings . read ( 'email' ) . then ( function ( result ) {
45
70
// attach the to: address to the request body so that it is available
46
71
// to the http api handler
@@ -51,15 +76,13 @@ apiRoutes = function (middleware) {
51
76
api . http ( api . mail . sendTest ) ( req , res ) ;
52
77
} ) ;
53
78
} ) ;
54
- // ## Slugs
55
- router . get ( '/ghost/api/v0.1/slugs/:type/:name' , api . http ( api . slugs . generate ) ) ;
56
- // ## Authentication
57
- router . post ( '/ghost/api/v0.1/authentication/passwordreset' , api . http ( api . authentication . generateResetToken ) ) ;
58
- router . put ( '/ghost/api/v0.1/authentication/passwordreset' , api . http ( api . authentication . resetPassword ) ) ;
59
79
60
- router . post ( '/ghost/api/v0.1/authentication/invitation' , api . http ( api . authentication . acceptInvitation ) ) ;
61
80
62
- router . post ( '/ghost/api/v0.1/authentication/token' ,
81
+ // ## Authentication
82
+ router . post ( '/authentication/passwordreset' , api . http ( api . authentication . generateResetToken ) ) ;
83
+ router . put ( '/authentication/passwordreset' , api . http ( api . authentication . resetPassword ) ) ;
84
+ router . post ( '/authentication/invitation' , api . http ( api . authentication . acceptInvitation ) ) ;
85
+ router . post ( '/authentication/token' ,
63
86
middleware . addClientSecret ,
64
87
middleware . authenticateClient ,
65
88
middleware . generateAccessToken
0 commit comments