fusion-plugin-http-router
Register and handle Http routes in a fusion app.
Table of contents
Installation
yarn add fusion-plugin-http-router
Setup
// src/main.js;;; // Define your http routes and methods server sideconst handlers = __NODE__ && '/api': '/users': POST: async { const user = ; return user; } ':id': GET: async { return some: 'data' + id; } PUT: async { ; return some: 'data' + id; } delete: async { // Error Handling Example try ; catch e const error = 'Failed to delete user'; errorcode = 'DELETEUSER'; errormeta = custom: 'metadata' ; throw error; } '/book': ... ; { const app = <div />; if __NODE__ app; app; return app;};
API
Registration API
HttpRouter
The HttpRouter plugin. Registers http routes and handlers.
HttpRouterToken
The canonical token for the HttpRouter plugin. Typically, it should be registered with the HttpRouter plugin.
Dependencies
HttpHandlersToken
Configures what http Router handlers exist. Required. Server-only.
Types
type Args = { params: Object, query: Object, body: Object, files: Object} type HttpHandlers = { [string]: { [string]: (args: Args, ctx: Context) => any },}
You can register a value of type HttpHandlers
.
BodyParserOptionsToken
Configures the options for koa-body
, internally used for parsing. Optional. Server-only.