HTTP Service


HTTP Service enable mouting of http controllers safely made available within an application (or site’s) url space, without the use of routers. Due to the URL-pattern created, an http service will never conflict with other application url patterns. Services are in particular useful when used in the Site engine or webapps where URLs are not predictable.


To create a service, place an http controller file in the src/main/resources/services/ structure of your project. Each controller needs to be placed in a folder matching it’s name i.e.: src/main/resources/services/myservice/myservice.js

Example service controller

exports.get = function(req) {
  return {
    body: {
      time: new Date()
    contentType: 'application/json'



Services use the following mount pattern: **/_/service/<appname>/<servicename>. This means that a service can be invoked in multiple locations, i.e. or The context the service is mounted on can also be used by the controller as context.

As an example the service 'profileimage' will only work in context of a profile’s url. I.e. will service an image, but invoked elsewhere it will not work.


By default, services may by used by any client or user. At times, it makes sense to restrict access to the service based on user roles. This can be done without custom coding.

Sample descriptor limiting access to the service:



To safely generate a service URL, use the serviceUrl() function that is part of the Portal Library.

When invoked, the function will generate a contextual service url based on the context of the current controller.