Skip to content
spaceport / docs
The Spaceport handbook

HTTP Client — Overview

Spaceport includes a built-in HTTP client utility for making outbound requests to external APIs, webhooks, and services from your server-side code.

What It Is

The HTTP class is a static utility that wraps Apache HttpComponents, providing a simple Groovy-friendly interface for all standard HTTP methods: GET, POST, PUT, DELETE, and PATCH.

import spaceport.communications.http.HTTP

def response = HTTP.get('https://api.example.com/users')
if (response.statusCode == 200) {
    def users = response.body.jsonList()
}

When to Use It

Use the HTTP client whenever your application needs to communicate with external services:

Key Features

Quick Examples

GET with Query Parameters

def response = HTTP.get('https://api.example.com/search', [
    queryParams: [q: 'spaceport', limit: '10'],
    headers: ['Authorization': 'Bearer ' + apiKey]
])

if (response.statusCode == 200) {
    def results = response.body.jsonMap()
}

POST with JSON Body

def response = HTTP.post('https://hooks.example.com/notify', [
    body: [event: 'order_placed', orderId: orderId, total: 49.99],
    headers: ['X-Webhook-Secret': secret]
])

When the body is a Map or List, the content type is automatically set to application/json and the body is serialized via JsonBuilder.

See Also

Make the docs better.Edit this page on GitHub