Docs‎ > ‎API Creator‎ > ‎Create your API Project‎ > ‎

Create Custom Endpoints

Define your own RESTful endpoints by creating custom endpoints. These handlers are free-form and do not need to map to a specific data model. The JavaScript can implement any functionality and return a JSON response.

Unlike JavaScript Resource Types, Custom Endpoints can return any format (e.g., HTML), and have an option to not require an Authentication Token.  See the examples shown below.

Your custom endpoint is called for all URLs matching the contents of the URL. Your handler has access to the request object and can specify response headers, as in the following example:

responseHeaders.put('Content-Type', 'application/x-acme-special-json');
return JSON.stringify({
result: 'Hello',
uri: "" + request.getRequestURI(), // Partial path without host/port
url: "" + request.getRequestURL(), // Full URL
method: "" + request.getMethod(), // GET, POST, etc
pathInfo: "" + request.getPathInfo(), // /<account>/<project>/<path>
acceptHeader: "" + request.getHeader("Accept"), // Any HTTP header
fooParam: "" + request.getParameter("foo") // Gets value of e.g. ...?foo=123


The request object is a Java request object, or an instance of HttpServletRequest, and is different than the request objects you get in other contexts, such as in rules and events. When writing a handler, you take control and Live API Creator does not create a standard request object. The responseHeaders variable is a Java Map. You can call GET and PUT on it. If you do not specify a response header, application/json is returned by default.

Create Custom Endpoints

  1. With your API project open, from the Create menu, click Custom Endpoints.
  2. Click Add.
  3. Name your custom endpoint and then save your changes.
  4. Test your endpoint by copying the contents of the URL to a new browser page.

Deactivate Custom Endpoints

By default, the custom endpoints you create are active. Deactivate your custom endpoints by selecting the Active checkbox.

Custom Endpoints that Require an Auth Token

By default, requests to custom endpoint do not require authentication. You can indicate that requests to your custom endpoint require an auth token by selecting the Authentication checkbox.

Custom Endpoints that Return HTML

Custom endpoints can return HTML. For example, you can create simple HTML pages and return the content with the following code:

responseHeaders.put('Content-Type', 'text/html');

For example, the Business to Business Example defines the following custom endpoint:
Run this by copying the contents of the URL to a new browser page, as shown in the following image: