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'),
|
2014-07-10 03:48:00 +04:00
|
|
|
apiRoutes;
|
2013-11-12 09:27:12 +04:00
|
|
|
|
2014-04-12 07:46:15 +04:00
|
|
|
apiRoutes = function (middleware) {
|
|
|
|
var router = express.Router();
|
2014-07-09 02:28:31 +04:00
|
|
|
// alias delete with del
|
|
|
|
router.del = router.delete;
|
2014-04-12 07:46:15 +04: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 16:41:19 +04:00
|
|
|
// ## Posts
|
2014-07-09 02:28:31 +04:00
|
|
|
router.get('/posts', api.http(api.posts.browse));
|
|
|
|
router.post('/posts', api.http(api.posts.add));
|
|
|
|
router.get('/posts/:id', api.http(api.posts.read));
|
|
|
|
router.get('/posts/slug/:slug', api.http(api.posts.read));
|
|
|
|
router.put('/posts/:id', api.http(api.posts.edit));
|
|
|
|
router.del('/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-07-09 02:28:31 +04:00
|
|
|
router.get('/settings', api.http(api.settings.browse));
|
|
|
|
router.get('/settings/:key', api.http(api.settings.read));
|
|
|
|
router.put('/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-07-09 02:28:31 +04:00
|
|
|
router.get('/users', api.http(api.users.browse));
|
|
|
|
router.get('/users/:id', api.http(api.users.read));
|
|
|
|
router.get('/users/slug/:slug', api.http(api.users.read));
|
|
|
|
router.get('/users/email/:email', api.http(api.users.read));
|
|
|
|
router.put('/users/password', api.http(api.users.changePassword));
|
|
|
|
router.put('/users/:id', api.http(api.users.edit));
|
2014-07-11 16:17:09 +04:00
|
|
|
router.post('/users', api.http(api.users.add));
|
2014-07-09 02:28:31 +04:00
|
|
|
router.del('/users/:id', api.http(api.users.destroy));
|
2014-06-20 13:15:01 +04: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 16:41:19 +04:00
|
|
|
// ## Tags
|
2014-07-09 02:28:31 +04:00
|
|
|
router.get('/tags', api.http(api.tags.browse));
|
|
|
|
|
2014-07-15 19:22:06 +04:00
|
|
|
// ## Roles
|
|
|
|
router.get('/roles/', api.http(api.roles.browse));
|
|
|
|
|
2014-07-09 02:28:31 +04:00
|
|
|
// ## Slugs
|
|
|
|
router.get('/slugs/:type/:name', api.http(api.slugs.generate));
|
|
|
|
|
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-07-09 02:28:31 +04:00
|
|
|
router.get('/themes', api.http(api.themes.browse));
|
|
|
|
router.put('/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-07-09 02:28:31 +04:00
|
|
|
router.get('/notifications', api.http(api.notifications.browse));
|
|
|
|
router.post('/notifications', api.http(api.notifications.add));
|
|
|
|
router.del('/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-07-09 02:28:31 +04:00
|
|
|
router.get('/db', api.http(api.db.exportContent));
|
|
|
|
router.post('/db', middleware.busboy, api.http(api.db.importContent));
|
|
|
|
router.del('/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-07-09 02:28:31 +04:00
|
|
|
router.post('/mail', api.http(api.mail.send));
|
|
|
|
router.post('/mail/test', function (req, res) {
|
2014-06-26 22:22:52 +04:00
|
|
|
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-07-03 19:06:07 +04:00
|
|
|
|
|
|
|
|
2014-07-09 02:28:31 +04:00
|
|
|
// ## Authentication
|
|
|
|
router.post('/authentication/passwordreset', api.http(api.authentication.generateResetToken));
|
|
|
|
router.put('/authentication/passwordreset', api.http(api.authentication.resetPassword));
|
|
|
|
router.post('/authentication/invitation', api.http(api.authentication.acceptInvitation));
|
2014-07-11 16:17:09 +04:00
|
|
|
router.post('/authentication/setup', api.http(api.authentication.setup));
|
|
|
|
router.get('/authentication/setup', api.http(api.authentication.isSetup));
|
2014-07-09 02:28:31 +04:00
|
|
|
router.post('/authentication/token',
|
2014-07-17 16:22:07 +04:00
|
|
|
middleware.spamPrevention,
|
2014-06-30 16:58:10 +04:00
|
|
|
middleware.addClientSecret,
|
|
|
|
middleware.authenticateClient,
|
|
|
|
middleware.generateAccessToken
|
|
|
|
);
|
|
|
|
|
2014-07-15 14:40:14 +04:00
|
|
|
// ## Uploads
|
|
|
|
router.post('/uploads', middleware.busboy, api.http(api.uploads.add));
|
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;
|