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 16:41:19 +04:00
|
|
|
// # API routes
|
2014-04-12 07:46:15 +04:00
|
|
|
var express = require('express'),
|
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 16:41:19 +04:00
|
|
|
api = require('../api'),
|
|
|
|
apiRoutes;
|
2013-11-12 09:27:12 +04:00
|
|
|
|
2014-04-12 07:46:15 +04:00
|
|
|
apiRoutes = function (middleware) {
|
|
|
|
var router = express.Router();
|
|
|
|
|
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 16:41:19 +04:00
|
|
|
// ## Posts
|
2014-04-12 07:46:15 +04:00
|
|
|
router.get('/ghost/api/v0.1/posts', api.http(api.posts.browse));
|
|
|
|
router.post('/ghost/api/v0.1/posts', api.http(api.posts.add));
|
|
|
|
router.get('/ghost/api/v0.1/posts/:id(\\d+)', api.http(api.posts.read));
|
|
|
|
router.get('/ghost/api/v0.1/posts/:slug([a-z-]+)', api.http(api.posts.read));
|
|
|
|
router.put('/ghost/api/v0.1/posts/:id', api.http(api.posts.edit));
|
|
|
|
router['delete']('/ghost/api/v0.1/posts/:id', api.http(api.posts.destroy));
|
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 16:41:19 +04:00
|
|
|
// ## Settings
|
2014-04-12 07:46:15 +04:00
|
|
|
router.get('/ghost/api/v0.1/settings/', api.http(api.settings.browse));
|
|
|
|
router.get('/ghost/api/v0.1/settings/:key/', api.http(api.settings.read));
|
|
|
|
router.put('/ghost/api/v0.1/settings/', api.http(api.settings.edit));
|
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 16:41:19 +04:00
|
|
|
// ## Users
|
2014-04-12 07:46:15 +04:00
|
|
|
router.get('/ghost/api/v0.1/users/', api.http(api.users.browse));
|
|
|
|
router.get('/ghost/api/v0.1/users/:id/', api.http(api.users.read));
|
2014-06-20 13:15:01 +04:00
|
|
|
router.put('/ghost/api/v0.1/users/password/', api.http(api.users.changePassword));
|
2014-04-12 07:46:15 +04:00
|
|
|
router.put('/ghost/api/v0.1/users/:id/', api.http(api.users.edit));
|
2014-07-02 18:22:18 +04:00
|
|
|
router.post('/ghost/api/v0.1/users/', api.http(api.users.invite));
|
2014-06-20 13:15:01 +04:00
|
|
|
router['delete']('/ghost/api/v0.1/users/:id/', api.http(api.users.destroy));
|
|
|
|
|
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 16:41:19 +04:00
|
|
|
// ## Tags
|
2014-04-12 07:46:15 +04:00
|
|
|
router.get('/ghost/api/v0.1/tags/', api.http(api.tags.browse));
|
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 16:41:19 +04:00
|
|
|
// ## Themes
|
2014-04-12 07:46:15 +04:00
|
|
|
router.get('/ghost/api/v0.1/themes/', api.http(api.themes.browse));
|
|
|
|
router.put('/ghost/api/v0.1/themes/:name', api.http(api.themes.edit));
|
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 16:41:19 +04:00
|
|
|
// ## Notifications
|
2014-04-12 07:46:15 +04:00
|
|
|
router.get('/ghost/api/v0.1/notifications/', api.http(api.notifications.browse));
|
|
|
|
router.post('/ghost/api/v0.1/notifications/', api.http(api.notifications.add));
|
|
|
|
router['delete']('/ghost/api/v0.1/notifications/:id', api.http(api.notifications.destroy));
|
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 16:41:19 +04:00
|
|
|
// ## DB
|
2014-04-12 07:46:15 +04:00
|
|
|
router.get('/ghost/api/v0.1/db/', api.http(api.db.exportContent));
|
|
|
|
router.post('/ghost/api/v0.1/db/', middleware.busboy, api.http(api.db.importContent));
|
|
|
|
router['delete']('/ghost/api/v0.1/db/', api.http(api.db.deleteAllContent));
|
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 16:41:19 +04:00
|
|
|
// ## Mail
|
2014-04-12 07:46:15 +04:00
|
|
|
router.post('/ghost/api/v0.1/mail', api.http(api.mail.send));
|
2014-06-26 22:22:52 +04:00
|
|
|
router.post('/ghost/api/v0.1/mail/test', function (req, res) {
|
|
|
|
api.settings.read('email').then(function (result) {
|
|
|
|
// attach the to: address to the request body so that it is available
|
|
|
|
// to the http api handler
|
|
|
|
req.body = { to: result.settings[0].value };
|
|
|
|
|
|
|
|
api.http(api.mail.sendTest)(req, res);
|
|
|
|
}).catch(function () {
|
|
|
|
api.http(api.mail.sendTest)(req, res);
|
|
|
|
});
|
|
|
|
});
|
2014-06-20 13:15:01 +04:00
|
|
|
// ## Slugs
|
2014-04-12 07:46:15 +04:00
|
|
|
router.get('/ghost/api/v0.1/slugs/:type/:name', api.http(api.slugs.generate));
|
2014-06-20 13:15:01 +04:00
|
|
|
// ## Authentication
|
|
|
|
router.post('/ghost/api/v0.1/authentication/passwordreset', api.http(api.authentication.generateResetToken));
|
|
|
|
router.put('/ghost/api/v0.1/authentication/passwordreset', api.http(api.authentication.resetPassword));
|
2014-07-03 19:06:07 +04:00
|
|
|
|
|
|
|
router.post('/ghost/api/v0.1/authentication/invitation', api.http(api.authentication.acceptInvitation));
|
|
|
|
|
2014-06-30 16:58:10 +04:00
|
|
|
router.post('/ghost/api/v0.1/authentication/token',
|
|
|
|
middleware.addClientSecret,
|
|
|
|
middleware.authenticateClient,
|
|
|
|
middleware.generateAccessToken
|
|
|
|
);
|
|
|
|
|
2014-04-12 07:46:15 +04:00
|
|
|
|
|
|
|
return router;
|
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 16:41:19 +04:00
|
|
|
};
|
|
|
|
|
2014-05-06 02:38:05 +04:00
|
|
|
module.exports = apiRoutes;
|