Skip to content

App Functions SDK - Custom REST APIs

It is not uncommon to require your own custom REST APIs when building an Application Service. Rather than spin up your own webserver inside your app (alongside the already existing running webserver), we've exposed a method that allows you to add your own routes to the existing webserver. A few routes are reserved and cannot be used:

  • /api/v3/version
  • /api/v3/ping
  • /api/v3/config
  • /api/v3/trigger
  • /api/v3/secret

To add your own route, use the AddCustomRoute() API provided on the ApplicationService interface.

Example - Add Custom REST route

myhandler := func(c echo.Context) error {
  service.LoggingClient().Info("TEST")     
  c.Response().WriteHeader(http.StatusOK)
  c.Response().Write([]byte("hello"))   
}    

service := pkg.NewAppService(serviceKey)    
service.AddCustomRoute("/myroute", service.Authenticated, myHandler, "GET")    

Under the hood, this simply adds the provided route, handler, and method to the echo router used in the SDK. For more information on echo you can check out the GitHub repo here. You can access the interfaces.ApplicationService API for resources such as the logging client by pulling it from the context as shown above -- this is useful for when your routes might not be defined in your main.go where you have access to the interfaces.ApplicationService instance.