Skip to main content

HTTP

The HTTP module provides comprehensive HTTP client capabilities and web server functionality for Soul. It offers a JavaScript-like API for making HTTP requests, handling responses, and building web applications with middleware support, routing, and static file serving.

HTTP Client Operations

GET Request

Make a GET request to retrieve data:

POST Request

Send data with a POST request:

PUT Request

Update data with a PUT request:

PATCH Request

Partially update data with a PATCH request:

DELETE Request

Delete resources with a DELETE request:

HEAD Request

Get headers without response body:

OPTIONS Request

Get allowed methods for a resource:

Custom Requests

request - Make custom HTTP requests

Create fully customized HTTP requests:

Request Configuration

Headers

Set custom headers for requests:

Authentication

Configure basic authentication:

Timeout

Set request timeout:

Proxy Configuration

Configure proxy settings:

File Operations

Download Files

Download files from URLs:

Upload Files

Upload files to a server:

Response Handling

Response Object Structure

All HTTP methods return a response object with the following properties:

JSON Handling

Automatic JSON parsing for JSON responses:

Web Server Capabilities

Creating a Web Server

Create and configure a web server:

Middleware Support

Add middleware for request processing:

Request and Response Objects

Work with request and response objects:

Utility Functions

URL Encoding/Decoding

Handle URL encoding and decoding:

Query String Handling

Parse and build query strings:
Work with HTTP cookies:

Advanced Examples

API Client Example

REST API Server

Web Scraping Example

Webhook Handler

Best Practices

  1. Error Handling: Always check response status codes
  2. Timeouts: Set appropriate timeouts for long-running requests
  3. Headers: Use proper content types and authorization headers
  4. JSON: Leverage automatic JSON parsing and serialization
  5. Security: Use HTTPS, validate inputs, and implement proper authentication
The HTTP module provides a complete solution for HTTP communication in Soul, supporting both client-side requests and server-side web applications with modern features like middleware, routing, and JSON handling.