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 13:41:19 +01:00
|
|
|
// # API routes
|
2014-04-11 23: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 13:41:19 +01:00
|
|
|
api = require('../api'),
|
2014-07-09 18:48:00 -05:00
|
|
|
apiRoutes;
|
2013-11-12 00:27:12 -05:00
|
|
|
|
2014-04-11 23:46:15 -04:00
|
|
|
apiRoutes = function (middleware) {
|
|
|
|
var router = express.Router();
|
2014-07-08 23:28:31 +01:00
|
|
|
// alias delete with del
|
|
|
|
router.del = router.delete;
|
2014-04-11 23:46:15 -04:00
|
|
|
|
2014-08-20 21:42:34 +00: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 13:41:19 +01:00
|
|
|
// ## Posts
|
2014-07-08 23:28:31 +01: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 13:41:19 +01:00
|
|
|
// ## Settings
|
2014-07-08 23:28:31 +01: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 13:41:19 +01:00
|
|
|
// ## Users
|
2014-07-08 23:28:31 +01: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 17:40:30 +02:00
|
|
|
router.put('/users/owner', api.http(api.users.transferOwnership));
|
2014-07-08 23:28:31 +01:00
|
|
|
router.put('/users/:id', api.http(api.users.edit));
|
2014-07-11 14:17:09 +02:00
|
|
|
router.post('/users', api.http(api.users.add));
|
2014-07-08 23:28:31 +01:00
|
|
|
router.del('/users/:id', api.http(api.users.destroy));
|
2014-06-20 11:15:01 +02: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 13:41:19 +01:00
|
|
|
// ## Tags
|
2014-07-08 23:28:31 +01:00
|
|
|
router.get('/tags', api.http(api.tags.browse));
|
|
|
|
|
2014-07-15 16:22:06 +01:00
|
|
|
// ## Roles
|
|
|
|
router.get('/roles/', api.http(api.roles.browse));
|
|
|
|
|
2014-07-08 23:28:31 +01: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 13:41:19 +01:00
|
|
|
// ## Themes
|
2014-07-08 23:28:31 +01: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 13:41:19 +01:00
|
|
|
// ## Notifications
|
2014-07-08 23:28:31 +01: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 13:41:19 +01:00
|
|
|
// ## DB
|
2014-07-08 23:28:31 +01: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 13:41:19 +01:00
|
|
|
// ## Mail
|
2014-07-08 23:28:31 +01:00
|
|
|
router.post('/mail', api.http(api.mail.send));
|
|
|
|
router.post('/mail/test', function (req, res) {
|
2014-08-08 18:41:14 +01:00
|
|
|
api.http(api.mail.sendTest)(req, res);
|
2014-06-26 18:22:52 +00:00
|
|
|
});
|
2014-07-03 17:06:07 +02:00
|
|
|
|
2014-07-08 23:28:31 +01:00
|
|
|
// ## Authentication
|
2014-08-01 00:58:32 +02:00
|
|
|
router.post('/authentication/passwordreset',
|
2014-08-05 12:58:58 +02:00
|
|
|
middleware.spamForgottenPrevention,
|
2014-08-01 00:58:32 +02:00
|
|
|
api.http(api.authentication.generateResetToken)
|
|
|
|
);
|
2014-07-08 23:28:31 +01:00
|
|
|
router.put('/authentication/passwordreset', api.http(api.authentication.resetPassword));
|
|
|
|
router.post('/authentication/invitation', api.http(api.authentication.acceptInvitation));
|
2014-08-24 19:34:26 -07:00
|
|
|
router.get('/authentication/invitation', api.http(api.authentication.isInvitation));
|
2014-07-11 14:17:09 +02:00
|
|
|
router.post('/authentication/setup', api.http(api.authentication.setup));
|
|
|
|
router.get('/authentication/setup', api.http(api.authentication.isSetup));
|
2014-07-08 23:28:31 +01:00
|
|
|
router.post('/authentication/token',
|
2014-08-05 12:58:58 +02:00
|
|
|
middleware.spamSigninPrevention,
|
2014-06-30 14:58:10 +02:00
|
|
|
middleware.addClientSecret,
|
|
|
|
middleware.authenticateClient,
|
|
|
|
middleware.generateAccessToken
|
|
|
|
);
|
2014-09-01 18:02:46 +00:00
|
|
|
router.post('/authentication/revoke', api.http(api.authentication.revoke));
|
2014-06-30 14:58:10 +02:00
|
|
|
|
2014-07-15 12:40:14 +02:00
|
|
|
// ## Uploads
|
|
|
|
router.post('/uploads', middleware.busboy, api.http(api.uploads.add));
|
2014-04-11 23: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 13:41:19 +01:00
|
|
|
};
|
|
|
|
|
2014-05-06 00:38:05 +02:00
|
|
|
module.exports = apiRoutes;
|