-
Notifications
You must be signed in to change notification settings - Fork 0
Home
If you want to create a REST service in Dirigible, you will need aRESTme. It will enable you to configure HTTP endpoints and handlers that will service them without all the boilerplate around this. It comes in two separate, related modules. The arestme/http
module enables you to design any kind of HTTP services. The arestme/data_service
builds on arestme/http
to aid you in producing data-oriented services compliant with a standard protocol similar to OData.
The key component in arestme is the http
module (arestme/http
). It provides all the basic functionality to create HTTP services however you like to design them.
Example: To serve GET
requests to /services/js/myservice.js
resource and receive response with HTTP status code 200 and body payload "OK"
, create a myservice.js
file in a project's ScriptingServices section with the following contents:
require('arestme/http').get() .addResourceHandler("","get", function(ctx, io){ io.response.println('OK'); }).service();
Sending a GET
request to <host>/services/js/myservice.js
now will return HTTP code 200
and body content "OK"
. The dirigible console will also read something like this:
[arestme/HttpController] Serving request for resource [myservice.js], Verb[GET], Content-Type[], Accept["text/html", "application/xhtml+xml", "application/xml", "image/webp", "*/*"] finished
For full description of the capabilities of the module and reference how to use it refer to HttpController wiki page
-
get(oConfig)
Factory method for new HttpController instances.
-
oConfig
Object(optional) This controller instance configuration for resource handlers. See
HttpController#addResourceHandlers
parameter specification for schema and description.Returns: a new HttpController instance
Example:
var http = require("arestme/http").get();
-
-
HttpController
The constructor function of the HttpController class, implementing an HTTP service that handles the requests it has been configured for. The module exposes the class in case it is needed for extensions, for example for more specific protocols than HTTP, such as
DataService
inarestme/data_service
module. For details refer to the HttpController API.Example: New HttpController instance (same as invoking
get
as described above)var HttpController = require("arestme/http").HttpController; var http = new HttpController();
The data_service
(arestme/data_service
) leverages the http
module by introducing data access object functions bindings for the HTTP Data Service protocol. It allows you to easily plugin handlers for the HTTP Data Service protocols and, using the defaults, to bind a Data Service to a DAO object such as those provided by the daoism project and use it as backend service.
Example with DAO
var MyDAO = function(){}; MyDAO.prototype.list = function(){ return [{id:1, text:'topic 1'}, {id:2, text:'topic 2'}]; }; var svc = new DataService(new MyDAO()) svc.service(); Send an HTTP request for listing entity set (topics) entities (topic): GET /services/js/topics.js It should return [{id:1, text:'topic 1'}, {id:2, text:'topic 2'}]
For more extensive documentation and examples refer to Data Service wiki.
-
DataService
The constructor function of the DataService class. Creating a new instance of it an invoking its
service
method will service HTTP Data Service protocol requests. -
HandlersProvider
The constructor function of the HandlersProvider class. It is intended for extensions only. For example how to extend, see
DAOHandlersProvider
. -
DAOHandlersProvider
The constructor function of the DAOHandlersProvider class. It is provided public for customizations.