Refactor API arguments
closes #2610, refs #2697
- cleanup API index.js, and add docs
- all API methods take consistent arguments: object & options
- browse, read, destroy take options, edit and add take object and options
- the context is passed as part of options, meaning no more .call
everywhere
- destroy expects an object, rather than an id all the way down to the model layer
- route params such as :id, :slug, and :key are passed as an option & used
to perform reads, updates and deletes where possible - settings / themes
may need work here still
- HTTP posts api can find a post by slug
- Add API utils for checkData
2014-05-08 07:41:19 -05:00
|
|
|
// # API routes
|
2013-11-12 01:03:25 -05:00
|
|
|
var middleware = require('../middleware').middleware,
|
Refactor API arguments
closes #2610, refs #2697
- cleanup API index.js, and add docs
- all API methods take consistent arguments: object & options
- browse, read, destroy take options, edit and add take object and options
- the context is passed as part of options, meaning no more .call
everywhere
- destroy expects an object, rather than an id all the way down to the model layer
- route params such as :id, :slug, and :key are passed as an option & used
to perform reads, updates and deletes where possible - settings / themes
may need work here still
- HTTP posts api can find a post by slug
- Add API utils for checkData
2014-05-08 07:41:19 -05:00
|
|
|
api = require('../api'),
|
|
|
|
apiRoutes;
|
2013-11-12 00:27:12 -05:00
|
|
|
|
Refactor API arguments
closes #2610, refs #2697
- cleanup API index.js, and add docs
- all API methods take consistent arguments: object & options
- browse, read, destroy take options, edit and add take object and options
- the context is passed as part of options, meaning no more .call
everywhere
- destroy expects an object, rather than an id all the way down to the model layer
- route params such as :id, :slug, and :key are passed as an option & used
to perform reads, updates and deletes where possible - settings / themes
may need work here still
- HTTP posts api can find a post by slug
- Add API utils for checkData
2014-05-08 07:41:19 -05:00
|
|
|
apiRoutes = function (server) {
|
|
|
|
// ## Posts
|
|
|
|
server.get('/ghost/api/v0.1/posts', api.http(api.posts.browse));
|
|
|
|
server.post('/ghost/api/v0.1/posts', api.http(api.posts.add));
|
|
|
|
server.get('/ghost/api/v0.1/posts/:id(\\d+)', api.http(api.posts.read));
|
|
|
|
server.get('/ghost/api/v0.1/posts/:slug([a-z-]+)', api.http(api.posts.read));
|
|
|
|
server.put('/ghost/api/v0.1/posts/:id', api.http(api.posts.edit));
|
|
|
|
server.del('/ghost/api/v0.1/posts/:id', api.http(api.posts.destroy));
|
|
|
|
server.get('/ghost/api/v0.1/posts/slug/:title', api.http(api.posts.generateSlug));
|
|
|
|
// ## Settings
|
|
|
|
server.get('/ghost/api/v0.1/settings/', api.http(api.settings.browse));
|
|
|
|
server.get('/ghost/api/v0.1/settings/:key/', api.http(api.settings.read));
|
|
|
|
server.put('/ghost/api/v0.1/settings/', api.http(api.settings.edit));
|
|
|
|
// ## Users
|
|
|
|
server.get('/ghost/api/v0.1/users/', api.http(api.users.browse));
|
|
|
|
server.get('/ghost/api/v0.1/users/:id/', api.http(api.users.read));
|
|
|
|
server.put('/ghost/api/v0.1/users/:id/', api.http(api.users.edit));
|
|
|
|
// ## Tags
|
|
|
|
server.get('/ghost/api/v0.1/tags/', api.http(api.tags.browse));
|
|
|
|
// ## Themes
|
|
|
|
server.get('/ghost/api/v0.1/themes/', api.http(api.themes.browse));
|
|
|
|
server.put('/ghost/api/v0.1/themes/:name', api.http(api.themes.edit));
|
|
|
|
// ## Notifications
|
|
|
|
server.del('/ghost/api/v0.1/notifications/:id', api.http(api.notifications.destroy));
|
|
|
|
server.post('/ghost/api/v0.1/notifications/', api.http(api.notifications.add));
|
|
|
|
server.get('/ghost/api/v0.1/notifications/', api.http(api.notifications.browse));
|
|
|
|
server.post('/ghost/api/v0.1/notifications/', api.http(api.notifications.add));
|
|
|
|
server.del('/ghost/api/v0.1/notifications/:id', api.http(api.notifications.destroy));
|
|
|
|
// ## DB
|
|
|
|
server.get('/ghost/api/v0.1/db/', api.http(api.db.exportContent));
|
|
|
|
server.post('/ghost/api/v0.1/db/', middleware.busboy, api.http(api.db.importContent));
|
|
|
|
server.del('/ghost/api/v0.1/db/', api.http(api.db.deleteAllContent));
|
|
|
|
// ## Mail
|
|
|
|
server.post('/ghost/api/v0.1/mail', api.http(api.mail.send));
|
|
|
|
server.post('/ghost/api/v0.1/mail/test', api.http(api.mail.sendTest));
|
|
|
|
};
|
|
|
|
|
|
|
|
module.exports = apiRoutes;
|