# HTTP services

## Introduction

The HTTP Service Editor allows you to create simple REST services. The idea is that a form can call a service, typically passing XML back and forth.

To create a new HTTP service, click the Add icon under "HTTP Services". The HTTP Service Editor opens.

The following screenshot shows an example of filled-out service:

![Service Definition](https://4129616727-files.gitbook.io/~/files/v0/b/gitbook-legacy-files/o/assets%2F-LEkBiSDvlXs3VWiO0Zu%2F-LEkBmMpnaxnftLGDglW%2F-LEkC5u4IF5FsG3jk2bD%2Fservice-definition.png?generation=1528743360405888\&alt=media)

## Service definition

### Basic settings

The "Definition" tab allows you to set the basic service parameters:

* **Service Name**
  * This is the name of the service, as seen by Form Builder. Must start with a letter, and may not contain spaces.
* **Resource URL**
  * `HTTP` or `HTTPS` URL to which the service must be called.
* **Method**
  * The HTTP method to use: `GET`, `POST`, `PUT` or `DELETE`.
* **Serialization**
  * This applies to the `POST` and `PUT` methods.
  * **XML:** Sends the request body as XML (`application/xml`)
  * **HTML Form:** Sends the request body as HTML form data (`application/x-www-form-urlencoded`)
* **Request Body**
  * This applies to the `POST` and `PUT` methods.
  * The XML document to send to the service.

### URL parameters

\[SINCE Orbeon Forms 2016.1]

* This applies to the `GET` and `DELETE` methods.
* You can add as many URL parameters as needed.
* A non-blank URL parameter specifies a default value for the parameter.
* An action can set the value of a parameter.

Here is [how to set URL parameters from an action](https://doc.orbeon.com/~/revisions/-LFrzxlvP9UXA6_RDYI9/form-builder/advanced/actions#passing-url-parameters-to-get-and-delete-methods).

### JSON support

\[SINCE Orbeon Forms 2016.1]

A JSON *response* from a service is processed and converted to an XML document following the XForms 2.0 scheme (see [JSON support](https://doc.orbeon.com/~/revisions/-LFrzxlvP9UXA6_RDYI9/xforms/submission/json-support)).

As of Orbeon Forms 2016.1, it is not yet possible to *send* JSON to a service. See [#2480](https://github.com/orbeon/orbeon-forms/issues/2480) for details.

### URL Parameters before Orbeon Forms 2016.1

Prior to Orbeon Forms 2016.1, a "request body" is mandatory for the `GET` and `DELETE` methods. The body is not sent to the service, but instead is used to configure request parameters.

The content of the "Request Body" form has to be a well-formed XML document. The name of the root element doesn't matter, but usually `params`or `request` is used. Each child element defines a parameter as shown in the following example:

```markup
<params>
    <userId>1</userId>
    <userName>test</userName>
</params>
```

Here Orbeon invokes the URL:

```
$<Resource URL>?userId=1&userName=test
```

where `$<Resoure URL>` is the content of the input field "Resource URL".

Make sure to select `HTML Form` in the `Serialization` dropdown, otherwise the URL parameters are not appended to the request URL.

## Advanced parameters

The "Advanced" tab allows you to set advanced service parameters:

* **SOAP Service**
  * Whether this is a SOAP service
* **SOAP Action**
  * If selected, the value of the `SOAPAction` header.
* **HTTP Authentication**
  * Whether to use HTTP authentication.
  * **Username:** Username to use.
  * **Password:** Password to use.

![Advanced parameters](https://4129616727-files.gitbook.io/~/files/v0/b/gitbook-legacy-files/o/assets%2F-LEkBiSDvlXs3VWiO0Zu%2F-LEkBmMpnaxnftLGDglW%2F-LEkC5uOytD20VHhUICC%2Fservice-advanced.png?generation=1528743371070574\&alt=media)

## Testing a service

The Test button allows you to test the service. Before doing this, you have to set data in the request body for a `POST` or `PUT` request, or you might want to set URL parameters for a `GET` or `DELETE`. Form Builder executes the service, and then provides information about the response returned, including:

* Whether an error occurred (green or red highlight)
* URL called
* Response status code
* Response headers
* Response body

This helps you troubleshoot the service call.

![Testing a service](https://4129616727-files.gitbook.io/~/files/v0/b/gitbook-legacy-files/o/assets%2F-LEkBiSDvlXs3VWiO0Zu%2F-LEkBmMpnaxnftLGDglW%2F-LEkC5uRz95M7c6kp8oV%2Fservice-test.png?generation=1528743371105914\&alt=media)

## Saving the service

Once your service is defined, the "Save" buttons saves it to the form. You can come back to it and modify it later by clicking on the "Edit" icon next to the service name. You can also delete the service using the trashcan icon.

## Deleting a service

You can delete a saved service using the "Remove" button.

## See also

* [Actions](https://doc.orbeon.com/~/revisions/-LFrzxlvP9UXA6_RDYI9/form-builder/advanced/services-and-actions/actions)
* [Database services](https://doc.orbeon.com/~/revisions/-LFrzxlvP9UXA6_RDYI9/form-builder/advanced/services-and-actions/database-services)
