JSGI Requests and Responses

The JSGI (JavaScript Gateway Interface) specification defines an low-level interface between a HTTP server and JavaScript-based web applications. It has been developed by the CommonJS project and is implemented by Ringo. The main goal is to map incoming HTTP requests to arbitrary JavaScript objects. Application developers can use the request data, manipulate it, and generate a response object, which the JSGI implementation maps back to a valid HTTP response.

Between the HTTP server and the application, developers can include middleware functions. Middlewares can manipulate the request object, like parsing query parameters. They help to make application development easier. Web frameworks like stick provide a rich set of middlewares.

Request Object

Response Object

A JSGI application is a JavaScript function accepting exactly one argument which is the request object. It must return a valid response object. The response object has exactly three required properties: