Dabscm Library Reference

(scm net http client)

HTTP client — GET, POST, and other request methods

Overview

(scm net http client) is an HTTP client. The convenience procedures cover the common verbs (http-get, http-post, http-put, http-delete), plus JSON variants that set the appropriate Accept / Content-Type headers. For full control build a request with (scm net http request) and send it with http-send. Every call returns an http-response.

Common uses

(import (scm net http client))

(http-get "http://example.com/")                  ;; => an http-response
(http-post "http://example.com/items" "payload")  ;; POST a body

;; JSON helpers — http-get-json sends Accept: application/json,
;; http-post-json sends a JSON string body with Content-Type: application/json:
(http-get-json "http://example.com/api/items")
(http-post-json "http://example.com/api/items" "{\"name\":\"Ada\"}")

Responses are the records described in (scm net http response) — read their status, headers, and body with that library's accessors (and parse a JSON body yourself with (scm json simple)).

7 bindings

http-delete
Syntax: (http-delete url)
Library: (scm net http client)
Description: Performs an HTTP DELETE request and returns an http-response.
Example:
  (http-delete "http://example.com/item/1")
http-get
Syntax: (http-get url) (http-get url headers) (http-get url headers timeout-seconds)
Library: (scm net http client)
Description: Performs an HTTP GET request and returns an http-response object.
  Optional timeout-seconds overrides the default request timeout (600s); <= 0 means no timeout.
Example:
  (http-response-status (http-get "http://example.com/")) => 200
http-get-json
Syntax: (http-get-json url)
Library: (scm net http client)
Description: Performs an HTTP GET request with Accept: application/json header.
  Returns an http-response.
Example:
  (http-get-json "http://example.com/api/items")
http-post
Syntax: (http-post url body) (http-post url body headers) (http-post url body headers timeout-seconds)
Library: (scm net http client)
Description: Performs an HTTP POST request with the given body string and returns an http-response object.
  Optional timeout-seconds overrides the default request timeout (600s); <= 0 means no timeout.
Example:
  (http-post "http://example.com/api" "{}")
http-post-json
Syntax: (http-post-json url body)
Library: (scm net http client)
Description: Performs an HTTP POST with Content-Type: application/json. body should
  be a JSON string. Returns an http-response.
Example:
  (http-post-json "http://example.com/api" "{\"x\":1}")
http-put
Syntax: (http-put url body)
Library: (scm net http client)
Description: Performs an HTTP PUT request with the given body and returns an http-response.
Example:
  (http-put "http://example.com/item/1" "updated")
http-send
Syntax: (http-send request)
Library: (scm net http client)
Description: Sends an HTTP request object and returns an http-response object.
Example:
  (http-send (make-http-request "DELETE" "http://example.com/x" '() #f))