Extending routes into the write api plugin
-
I've seen in the write api plugin that there is a comment referring to plugins being able to add their own routes into the write api plugin.
Does this mean that we can extend the v1 api to route to an endpoint within a custom plugin? If so, how would you consume this, or is this feature not fully implemented yet?
Thanks.
-
@snodejoke This is implemented. The write-api fires off the following hook after it implements its own routes:
filter:plugin.write-api.routes
It passes in
router
,apiMiddleware
,middleware
, anderrorHandler
, so given that you can style your own routes like I do in the write api, e.g.:var addRoutes = function(data, callback) { data.router.get('/awesome', apiMiddleware.requireUser, function(req, res) { console.log('lorem ipsum!'); res.sendStatus(200); }); callback(null, data); });
In the above example, I used the
requireUser
middleware, which, provided by the write-api, means you have to pass in an user/master token just like the other routes. It also setsreq.user.uid
for you to use.