Skip to content

Home

Development

IDEs

JAR services

API Explorer

HttpFunctions

One of the most common transports used in applications, especially integrations, is HTTP. Martini includes functions that make it easy to build and send HTTP requests from Gloop. These functions, which reside in the Http class, provide everything you need to make an HTTP request including:

  • The ability to configure headers, cookies, redirect behaviour, and timeouts;
  • Automatic conversion of Gloop models to JSON, XML, YAML (when requesting), and vice-versa (when parsing responses);
  • Multiple authentication functions (including Basic, OAuth1 and OAuth2, Hawk, and AWS4); and
  • Built-in tracking of request and response data, which allows the HTTP call be be logged to Tracker

Calls to these functions can easily be dragged and dropped into your Gloop services just like any other function; but you can also generate these services using the HTTP Client's (in Martini Desktop) "Export as Service" feature. Using this feature, you can construct and repeatedly test an HTTP request against a real endpoint in the HTTP Client (like you would using a tool like Postman) before generating a service.

Once you're happy with the inputs and configuration of the request, you can export it. Exporting the request will create a new service which makes the equivalent HTTP request, along with the models required for the request and response. This effectively converts your custom request into a function in itself!

For use in Gloop only

Http contains Gloop-specific functions; hence, are not recommended for use in Groovy. If you want to send requests in Groovy, use HttpClientFunctions instead.

Logging HTTP traffic

The Martini HTTP client uses Apache HttpComponents to perform HTTP requests. If you would like to have the traffic from the client logged to the Martini console, change the logging level of the org.apache.http.wire category to DEBUG.

HTTP client logging set to debug

http

The io.toro.martini.Http.http(...) function is used for sending RESTful HTTP requests to a web server.

Parameters

Property Type Description
request GloopModel, io.toro.martini.http.Request A model containing the details of the request. The properties of this model will depend on the requirements of the receiving HTTP endpoint.
auth GloopModel, io.toro.martini.http.Auth A model containing the authentication information of the request.
returnAs java.lang.String The return type of the response. The response can be an InputStream, String, byte[], or a GloopObject.
responseType java.lang.String The content type of the response obtained; the options are: XML, JSON, or Auto-detect.
throwHttpExceptions java.lang.Boolean Indicates whether an exception should be thrown if the HTTP response code is 5xx.
trackable GloopModel, io.toro.martini.tracker.Trackable A model indicating the tracking options for the call; will be used by Martini's Tracker engine.

Return value

This function will return a io.toro.martini.http.Response Gloop model which will contain the data sent back by the server as a response to the request.

Usage

Sample service showing how to use the `http(...)` function of `Http`

The http(...) function requires at least two arguments

The http(...) function requires you to at least provide the function and uri parameters in your request. Otherwise, Gloop will throw an error.

soap

The io.toro.martini.Http.soap(...) function is used for sending SOAP requests to a SOAP web server.

Parameters

Property Type Description
url java.lang.String URL of the receiving SOAP web service.
auth GloopModel, io.toro.martini.http.Auth A model containing the authentication information of the request.
soapAction java.lang.String The name of the SOAP action to call.
style java.lang.String Messaging style of the SOAP Request; it can be either document or RPC.
soapProtocol java.lang.String Indicates the SOAP version to be used.
messageHeader GloopModel Header data to be sent along with the request.
messageBody GloopModel The body of the SOAP message. This is the data inside the <soap:Body></soap:Body> element.
trackable GloopModel, io.toro.martini.tracker.Trackable A model indicating the tracking options for the call; will be used by Martini's Tracker engine.

Return value

This function will return a io.toro.martini.http.Response Gloop model which will contain the data sent back by the server as a response to the request.

Usage

Sample service showing how to use the `soap(...)` function of `Http`

Required properties

This function requires you to at least provide the url and soapAction properties in order to send a request successfully.


  1. More specifically, sending requests and mapping their response to models