Skip to main content

HTTP Service

HTTP services expose your integration logic as REST endpoints that clients can call over HTTP. Use them when you need to receive requests, respond with data, or build webhooks. This page covers the configuration options for the listener, service, and resources, including how to define response schemas.

Creating an HTTP service

  1. Select + Add Artifact in the design view, or + next to Entry Points in the sidebar.
  2. Select HTTP Service under Integration as API.
  3. Fill in the creation form fields and select Create.
HTTP Service creation form showing Service Contract, Service Base Path, and Advanced ConfigurationsHTTP Service creation form showing Service Contract, Service Base Path, and Advanced Configurations

Service Contract

OptionDescription
Design From ScratchCreates a new service with empty resources. Default selection.
Import From OpenAPI SpecificationGenerates service stubs from an existing OpenAPI (Swagger) file or URL. Use this when you have an existing API contract.

Service Base Path

FieldDescription
Service Base PathURL prefix for all resources in this service (for example, /api). Must not end with / unless it is the bare root /.

Advanced Configurations

Expand Advanced Configurations to choose the HTTP listener:

OptionDescription
Shared Listener (Port 9090)Attaches the service to the project's shared HTTP listener on port 9090. Use this when multiple services share the same port.
Custom ListenerCreates a dedicated listener for this service. Enter the port in the Listener Port field that appears. Use this when the service needs its own port or TLS configuration.

After selecting Create, WSO2 Integrator opens the service in the Service Designer. The header shows the attached listener pill and the service base path. Select + Add Resource to add HTTP endpoints and then select any resource row to open it in the flow designer and build the integration logic.

Service configuration

Service configuration controls the base path and advanced service-level settings such as CORS policy, authentication, and payload validation.

In the Service Designer, select Configure in the service header to open the HTTP Service Configuration form. The form has two parts: the Base Path field at the top, and an expandable Service Configuration section for advanced settings.

FieldDescription
Base PathURL prefix for all resources in this service (for example, /api). Changing this field updates the service declaration in the code. Required.

Expand Service Configuration and select the edit icon to open the record editor. Settings configured here apply to all resources in the service unless a resource overrides them. See Service configuration fields below for the full list.

Service configuration fields

FieldDescription
hostVirtual host name used to identify this service when multiple services share the same listener.
compressionControls response compression. Configure the compression algorithm and which content types to compress.
chunkingChunked transfer encoding mode for responses. Options: AUTO (default), ALWAYS, NEVER.
corsCORS policy applied to all resources in this service. Configure allowed origins, methods, and headers.
authAuthentication handlers applied at the service level. All resources inherit this setting unless overridden.
mediaTypeSubtypePrefixCustom prefix added to the media type subtype in the Content-Type response header.
treatNilableAsOptionalWhen enabled (default), nilable-typed parameters are treated as optional in the request.
openApiDefinitionInline OpenAPI definition attached to the service for documentation and validation purposes.
validationWhen enabled (default), validates inbound request payloads against the declared schema.
serviceTypeOverrides the default service dispatch behavior. Use for advanced routing scenarios.
basePathOverride the base path declared on the service, useful when attaching the service to a different path at runtime.
laxDataBindingWhen enabled, allows data binding to succeed even if the payload contains extra fields not in the schema.

Listener configuration

The listener binds to a port and handles incoming HTTP connections.

In the HTTP Service Configuration panel, select Http Listener under Attached Listeners to configure the listener.

Configuring the HTTP default listener

When your service is attached to the shared HTTP default listener, listener settings are managed through configurable variables rather than the listener panel. To configure them:

  1. In the sidebar, select Configurations.
  2. Under Imported libraries, select ballerina/http.
  3. Scroll to the defaultListenerConfig section.
Default listener configuration in the Configurables panelDefault listener configuration in the Configurables panel

For standard HTTP setups, only Port is required. Configure Secure Socket to enable HTTPS. See Listener configuration fields below for the full list.

Select + Attach Listener at the bottom of the panel to attach an additional listener or to select an existing named listener.

Listener configuration fields

FieldDescriptionDefault
PortListening port of the HTTP service listener. Required.
HostHost name or IP address the listener binds to.0.0.0.0
HTTP1 SettingsHTTP/1.x protocol settings (keep-alive, max pipelined requests).{}
Secure SocketTLS/SSL configuration. Configure this to enable HTTPS.()
HTTP VersionHighest HTTP version the endpoint supports.HTTP/2.0
TimeoutRead/write timeout in seconds. Set to 0 to disable.60
ServerValue for the Server response header.()
Request LimitsInbound size limits for URI, headers, and request body.{}
Graceful Stop TimeoutGrace period in seconds before the listener force-stops.0
Socket ConfigServer socket settings (e.g., soBackLog queue length).{}
HTTP2 Initial Window SizeInitial HTTP/2 flow-control window size in bytes.65535
Min Idle Time In Stale StateMinimum seconds to hold an HTTP/2 connection open after GOAWAY. Set to -1 to close after all in-flight streams finish.300
Time Between Stale EvictionInterval in seconds between HTTP/2 stale connection eviction runs.30

Resources

Resources define the HTTP endpoints of a service. Each resource maps an HTTP method and path to the request inputs it accepts and the responses it can return.

Defining inputs

Select + Add Resource in the Service Designer to open the resource creation form. Set the HTTP method and path, then add the parameters the resource accepts. Select Save to add the resource to the service. Select the resource row to open it in the flow designer.

FieldDescription
HTTP MethodHTTP verb the resource responds to. Options: GET, POST, PUT, DELETE, PATCH, HEAD, OPTIONS.
Resource PathPath segment appended to the service base path (for example, orders gives the full path /api/orders). Use . to match the service base path itself.
Path ParamAdds a variable segment to the URL path. The client supplies the value inline in the URL (for example, /orders/{id}). Each path param becomes a typed parameter in the resource function. Supported types: string, int, float, boolean, decimal.
Query ParameterAdds a named URL query parameter extracted from the request URI (for example, ?artist=Coltrane). Can be optional (nilable type) or given a default value so the resource can be called without it.
HeaderBinds a specific request header to a named parameter. The parameter name must match the header name.
Define PayloadDefines the expected schema for the request body. Available for POST, PUT, PATCH, DELETE, and DEFAULT methods.

When you open an existing resource for editing, the Advanced Parameters section becomes available. These are low-level abstractions that underpin data binding, header mapping, and query parameter mapping. In most cases, the named parameters above (path params, query params, headers, payload) are sufficient. Reach for Request or Caller only for advanced scenarios such as gateways, proxy services, or multipart handling.

ParameterDescription
RequestThe complete http:Request object. Provides access to all headers, the raw body stream, query parameters, and request metadata. Use for advanced scenarios where named parameters are not enough. Typical examples: reading a streaming body, handling multipart payloads, and forwarding requests in a proxy or gateway.
HeadersAll request headers as a structured http:Headers collection. Use when you need to read or iterate over headers dynamically rather than binding individual named headers.
CallerThe http:Caller for sending responses imperatively. When present, the resource return type is constrained to error?. Use for scenarios such as sending 100 Continue before processing, or performing work after the response is already dispatched to the client.

Defining response schemas

The Responses panel declares every HTTP response the resource can return. Defining responses explicitly gives you compiler validation on the return values and produces an accurate OpenAPI specification. Select + Response to open the Response Configuration form for a new entry, or select the edit icon on an existing row.

FieldDescription
Status CodeHTTP status code for this response (for example, 200 - Ok, 201 - Created, 404 - Not Found).
Response Body SchemaData type of the response body. Leave empty for responses with no body (for example, 204 No Content).
Content TypeValue for the Content-Type response header. When left empty, the type is inferred from the body schema: application/json for records and maps, text/plain for strings, and application/octet-stream for byte arrays.
HeadersAdditional response headers to include in this response. Select + Add to define each header name and type.
Make This Response ReusableWhen checked, this response definition is extracted as a shared type that other resources in the service can reference.

When multiple response entries are defined, the resource selects which one to return at runtime based on the integration logic.

Status code options
  • Standard status codes: select any standard HTTP status code from the dropdown (for example, 200 - Ok, 201 - Created, 404 - Not Found). For POST resources, the framework defaults to 201 Created. For all other methods, it defaults to 200 OK.
  • Error type: select error as the response type to map unhandled Ballerina errors to 500 Internal Server Error automatically.
  • Dynamic response: at the end of the dropdown, Response type lets you define the status code, body, and headers dynamically inside the flow instead of fixing them at design time. Use this when the response shape varies based on runtime conditions.

Advanced configurations

Select Advanced Configurations in the resource edit panel to configure settings specific to this resource. These settings override the service-level defaults for this resource only.

FieldDescription
nameCustom name for this resource, used for display and documentation purposes.
consumesMedia types the resource accepts in the request body (for example, application/json, application/xml). Requests with a different Content-Type are rejected.
producesMedia types the resource can return in the response body.
corsCORS policy specific to this resource, overriding the service-level CORS setting.
authAuthentication configuration for this resource, overriding the service-level authentication setting.
transactionInfectableWhen enabled, allows a client-initiated distributed transaction to propagate into this resource.
linkedToLinks this resource to related resources for navigation and documentation purposes.

Select Add more resources before selecting Save to add another resource without closing the form.

Error handling

HTTP resource functions communicate errors through typed return values. Declare status code response types in the function signature to make error contracts explicit.

Use the Responses panel to declare the error responses a resource can return. The framework handles two categories of errors automatically:

  • Application errors: errors returned or propagated with check from resource logic are caught by the listener and converted to 500 Internal Server Error responses with the error message in the payload.
  • Framework errors: errors from the listener itself (missing resource: 404, failed data binding: 400, failed authorization: 401) are converted to their respective status codes.

To override the default behavior, add explicit error response entries in the Responses panel:

ApproachWhen to use
Add a 4xx or 5xx response entryWhen the resource should return a specific status code for a known error condition (for example, 404 Not Found when a record does not exist).
Select error as the response typeWhen you want the framework to map any unhandled Ballerina error to 500 Internal Server Error automatically.
Select Response type (dynamic)When the error status code and body are determined at runtime inside the flow.

For each error response with a body, set the Response Body Schema to document the error payload type. This improves the OpenAPI specification and enables tooling support.

See Defining response schemas for the full configuration reference.

What's next

  • Connections — configure HTTP client connections to call external services
  • Data Mapper — transform request/response payloads between formats
  • Try It for HTTP — send requests to your HTTP service from the built-in Try It panel