HTTP Methods
Standard HTTP methods
Achieve provides built-in handling for GET, HEAD, POST, and OPTIONS.
GET
A GET request follows normal resource routing. Achieve serves a static resource or invokes a JavaScript Servlet. For a servlet, query-string parameters are available through session.params.
HEAD
A HEAD request follows the same routing and processing as GET. Servlets are invoked normally, and the resulting status and headers are preserved, but response body bytes are suppressed.
POST
A POST request follows normal resource routing. For a servlet, Achieve automatically parses JSON and URL-encoded form bodies into session.params. Other content types remain available through the raw session.request stream. See the Servlet Session Object for parameter and request-object details.
OPTIONS
Achieve handles OPTIONS automatically without invoking a servlet. It returns 204 No Content with an Allow header listing the built-in methods and any registered additional methods.
OPTIONS and CORS
An ordinary OPTIONS request returns the methods supported by the server. When a request includes both Origin and Access-Control-Request-Method, Achieve treats it as a CORS preflight request and applies the configured CORS policy to the requested resource.
An approved preflight returns 204 No Content with Allow, Access-Control-Allow-Origin, Access-Control-Allow-Methods, and Access-Control-Allow-Headers. A cross-origin request without matching permission is refused with 403. See allowOrigins() for CORS configuration.
OPTIONS * is a server-wide capability request. It returns 204 No Content and the Allow header without performing resource lookup or CORS-policy matching.
Registering additional methods
setAppPath() must select the application space before an additional method is registered. Register one servlet handler for the method:
achieve.registerMethod(
"DELETE",
"methods/delete.jss"
);
The handler path is relative to the configured application space. Supported handler files use .jss, .jss.cjs, or .jss.mjs.
The handler receives the normal servlet session object. It can inspect the method and the complete requested URL:
exports.servlet = function(session) {
return JSON.stringify({
method: session.request.method,
url: session.request.url
});
};
The handler is selected by HTTP method, not by requested URL. Registering DELETE does not create separate URL-specific DELETE routes: every DELETE request is sent to the registered DELETE handler.
Registered-method behavior
Registered handlers bypass normal resource routing and the built-in GET and POST parameter parsing. session.params is initially empty; Achieve does not automatically parse the request query or body for these handlers. The handler can inspect session.request.url and consume the session.request stream directly.
Normal servlet behavior still applies, including returned values and Promises, session.autoEnd, response-status selection, and caught-error handling. See Backend: JavaScript Servlets for response completion and the Servlet Session Object for the request and response objects.
CORS authorization occurs before a registered handler is invoked. Registered methods are included in the Allow and Access-Control-Allow-Methods response headers.
Restrictions and unsupported methods
An unregistered method receives 501 Not Implemented.
GET, HEAD, POST, OPTIONS, and CONNECT cannot be registered. A custom method name must be a valid HTTP token, and each method name can be registered only once. Method names are matched exactly; registration does not normalize their case.
The handler path must remain within the configured application space and identify a supported servlet file. Registration rejects invalid handler paths. If a registered handler cannot be loaded or executed, Achieve handles the error and returns a 500 response when possible.