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
|
|
|
|
2015-06-14 22:07:52 +03:00
|
|
|
apiRoutes = function apiRoutes(middleware) {
|
2014-04-12 07:46:15 +04:00
|
|
|
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
|
|
|
|
2014-08-21 01:42:34 +04:00
|
|
|
// ## Configuration
|
|
|
|
router.get('/configuration', api.http(api.configuration.browse));
|
|
|
|
router.get('/configuration/:key', api.http(api.configuration.read));
|
|
|
|
|
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));
|
2014-07-30 19:40:30 +04:00
|
|
|
router.put('/users/owner', api.http(api.users.transferOwnership));
|
2014-07-09 02:28:31 +04:00
|
|
|
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-11-05 13:16:49 +03:00
|
|
|
router.get('/tags/:id', api.http(api.tags.read));
|
2015-06-11 04:42:17 +03:00
|
|
|
router.get('/tags/slug/:slug', api.http(api.tags.read));
|
2014-11-05 13:16:49 +03:00
|
|
|
router.post('/tags', api.http(api.tags.add));
|
|
|
|
router.put('/tags/:id', api.http(api.tags.edit));
|
|
|
|
router.del('/tags/:id', api.http(api.tags.destroy));
|
2014-07-09 02:28:31 +04:00
|
|
|
|
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));
|
2015-05-05 14:50:21 +03:00
|
|
|
router.post('/mail/test', api.http(api.mail.sendTest));
|
2014-07-03 19:06:07 +04:00
|
|
|
|
2014-07-09 02:28:31 +04:00
|
|
|
// ## Authentication
|
2014-08-01 02:58:32 +04:00
|
|
|
router.post('/authentication/passwordreset',
|
2015-05-26 22:04:27 +03:00
|
|
|
middleware.spamPrevention.forgotten,
|
2014-08-01 02:58:32 +04:00
|
|
|
api.http(api.authentication.generateResetToken)
|
|
|
|
);
|
2014-07-09 02:28:31 +04:00
|
|
|
router.put('/authentication/passwordreset', api.http(api.authentication.resetPassword));
|
|
|
|
router.post('/authentication/invitation', api.http(api.authentication.acceptInvitation));
|
2014-08-25 06:34:26 +04:00
|
|
|
router.get('/authentication/invitation', api.http(api.authentication.isInvitation));
|
2014-07-11 16:17:09 +04:00
|
|
|
router.post('/authentication/setup', api.http(api.authentication.setup));
|
2015-05-27 07:14:43 +03:00
|
|
|
router.put('/authentication/setup', api.http(api.authentication.updateSetup));
|
2014-07-11 16:17:09 +04:00
|
|
|
router.get('/authentication/setup', api.http(api.authentication.isSetup));
|
2014-07-09 02:28:31 +04:00
|
|
|
router.post('/authentication/token',
|
2015-05-26 22:04:27 +03:00
|
|
|
middleware.spamPrevention.signin,
|
2015-06-14 22:07:52 +03:00
|
|
|
middleware.api.addClientSecret,
|
|
|
|
middleware.api.authenticateClient,
|
|
|
|
middleware.api.generateAccessToken
|
2014-06-30 16:58:10 +04:00
|
|
|
);
|
2014-09-01 22:02:46 +04:00
|
|
|
router.post('/authentication/revoke', api.http(api.authentication.revoke));
|
2014-06-30 16:58:10 +04:00
|
|
|
|
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
|
|
|
|
2015-06-14 22:07:52 +03:00
|
|
|
// API Router middleware
|
|
|
|
router.use(middleware.api.methodNotAllowed);
|
|
|
|
|
|
|
|
router.use(middleware.api.errorHandler);
|
|
|
|
|
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;
|