UNPKG

3.47 kBJavaScriptView Raw
1/**
2 * @class APIBuilder.Router
3 * A Route is one part of the API Builder Web component, which is used to display HTML content
4 * to the client. A Route defines the API endpoint used by the service and
5 * the logic to execute to render the view files.
6 *
7 * ### Create a Router Endpoint
8 *
9 * To create a Router, define a new Router instance with the Router constructor,
10 * then bind the Router instance to the API Builder server's app instance.
11 *
12 * Pass an implementation object, API Builder configuration object and API Builder instance to the
13 * constructor. Set any Router properties on the implementation object except the ones marked
14 * non-creation. The {@link #name} property must be set.
15 *
16 * To render a view file, in the `action` function, invoke the
17 * [render()](http://expressjs.com/4x/api.html#res.render) method on the response object. Pass the
18 * view file, located in the `./web/views` folder, to render minus the file extension and the data
19 * to apply to the template. API Builder selects the renderer engine to use based on the extension
20 * of the view file.
21 *
22 * After creating the Router instance, call its [bind()](#bind) method and pass it an app instance.
23 *
24 * var foo = new APIBuilder.Router({
25 * name: 'foo',
26 * path: '/foo',
27 * method: 'GET',
28 * description: 'Render the foo view',
29 * action: function (req, res, next) {
30 * res.render('foo', {foobar: 'hello', foobaz: 'world'});
31 * next();
32 * }
33 * }, server.config, server);
34 * foo.bind(server.app);
35 *
36 * Alternatively, you can define your Routes using JavaScript files, which are automatically loaded
37 * by the API Builder service. For details, see the [API Builder Web
38 * guide](https://docs.axway.com/bundle/API_Builder_4x_allOS_en/page/api_builder_web.html).
39 */
40
41/**
42 * @constructor
43 * Creates a new Router instance.
44 * @param {Dictionary<APIBuilder.Router>} impl Implementation object.
45 * Set any Router properties on the object except the ones marked non-creation.
46 * The {@link #name} property must be set.
47 * @param {Object} config API Builder configuration object.
48 * @param {APIBuilder} apibuilder APIBuilder instance.
49 * @throws Error Missing `name` parameter.
50 */
51
52/**
53 * @property {Function} action
54 * Logic to execute when the endpoint is invoked by a client.
55 * The function is passed a request object, response object and next() function.
56 * You should always make sure that the action function calls the next() function
57 * regardless if the result is a success or an error.
58 */
59/**
60 * @property {APIBuilder} apibuilder
61 * @nonCreation
62 * API Builder instance associated with the Router instance.
63 */
64/**
65 * @property {Object} config
66 * @nonCreation
67 * Configuration object used to initialize the Router instance.
68 */
69/**
70 * @property {String} description
71 * Human-readable description of the API, which is used by the generated API documentation.
72 */
73/**
74 * @property {String} filename
75 * @nonCreation
76 * File used to load the Router instance.
77 */
78/**
79 * @property {String} method
80 * HTTP verb: `GET`, `PUT`, `POST` or `DELETE`.
81 */
82/**
83 * @property {String} name
84 * Name of the route used for identification.
85 */
86/**
87 * @property {String} path
88 * API endpoint.
89 */
90/**
91 * @property {Object} route
92 * @nonCreation
93 * Express route instance that binds the endpoint to the logic.
94 */
95/**
96 * @property {String} timestamp
97 * @nonCreation
98 * Datetime when the route was last synced.
99 */