← All procedures

http.request

Send an HTTP request and give the status, the headers and the body

CLI
Package
@procedures/http · README
Path
["http","request"]
CLI
mark http request --url <string>
As data
{"$proc":["http","request"],"input":{}}

Use it

In TypeScript

import { Client, LocalTransport, PROCEDURE_REGISTRY } from "@procedures/client";
import "@procedures/http/register"; // registers its procedures

const client = new Client(new LocalTransport({ registry: PROCEDURE_REGISTRY }));
const result = await client.exec(["http","request"], { url: "<url>" });
console.log(JSON.stringify(result));

From the command line

$ mark http request --url <string>

As data, in a program

{ "$proc": ["http", "request"], "input": { "url": "<url>" } }

Input

FieldTypeRequiredDefaultDescription
urlstringyesThe URL: http: or https:
method"GET" | "HEAD" | "POST" | "PUT" | "PATCH" | "DELETE" | "OPTIONS"noThe method (default: GET)
headersobjectnoThe headers of the request
queryobjectnoMore parameters for the query of the URL. A list gives the parameter more than one time
bodystringnoA body of text
jsonanynoA body of JSON: the procedure sets content-type: application/json
bodyBase64stringnoA body of bytes in base64
responseType"text" | "json" | "bytes"noThe form of the body of the response: text (default), json, or bytes in base64
timeoutMsintegernoThe time of the whole call, in milliseconds (default: 30000)
maxResponseBytesintegernoThe largest body of the response, in bytes. The default and the maximum is the limit of the module (10 MiB)
redirect"follow" | "manual" | "error"noWhat to do with a redirect: follow it (default), give it (manual), or fail (error)
maxRedirectsintegernoThe most redirects that the call follows (default: 5)

Output

FieldTypeRequiredDefaultDescription
statusintegeryesThe status of the response
statusTextstringyesThe reason phrase of the status
okbooleanyesTrue for a status in 200 to 299
urlstringyesThe URL of the response: the last URL after the redirects
redirectedbooleanyesTrue when the call followed a redirect
headersobjectyesThe headers of the response, with names in lowercase
bodyanyyesThe body: text, parsed JSON (null when empty), or bytes in base64
bytesintegeryesThe size of the body in bytes, after the content encoding
JSON Schemas
{
  "input": {
    "type": "object",
    "properties": {
      "url": {
        "type": "string",
        "format": "uri",
        "description": "The URL: http: or https:"
      },
      "method": {
        "description": "The method (default: GET)",
        "type": "string",
        "enum": [
          "GET",
          "HEAD",
          "POST",
          "PUT",
          "PATCH",
          "DELETE",
          "OPTIONS"
        ]
      },
      "headers": {
        "description": "The headers of the request",
        "type": "object",
        "propertyNames": {
          "type": "string"
        },
        "additionalProperties": {
          "type": "string"
        }
      },
      "query": {
        "description": "More parameters for the query of the URL. A list gives the parameter more than one time",
        "type": "object",
        "propertyNames": {
          "type": "string"
        },
        "additionalProperties": {
          "anyOf": [
            {
              "type": [
                "string",
                "number",
                "boolean"
              ]
            },
            {
              "type": "array",
              "items": {
                "type": [
                  "string",
                  "number",
                  "boolean"
                ]
              }
            }
          ]
        }
      },
      "body": {
        "description": "A body of text",
        "type": "string"
      },
      "json": {
        "description": "A body of JSON: the procedure sets content-type: application/json"
      },
      "bodyBase64": {
        "description": "A body of bytes in base64",
        "type": "string",
        "format": "base64",
        "contentEncoding": "base64",
        "pattern": "^$|^(?:[0-9a-zA-Z+/]{4})*(?:(?:[0-9a-zA-Z+/]{2}==)|(?:[0-9a-zA-Z+/]{3}=))?$"
      },
      "responseType": {
        "description": "The form of the body of the response: text (default), json, or bytes in base64",
        "type": "string",
        "enum": [
          "text",
          "json",
          "bytes"
        ]
      },
      "timeoutMs": {
        "description": "The time of the whole call, in milliseconds (default: 30000)",
        "type": "integer",
        "exclusiveMinimum": 0,
        "maximum": 86400000
      },
      "maxResponseBytes": {
        "description": "The largest body of the response, in bytes. The default and the maximum is the limit of the module (10 MiB)",
        "type": "integer",
        "exclusiveMinimum": 0,
        "maximum": 9007199254740991
      },
      "redirect": {
        "description": "What to do with a redirect: follow it (default), give it (manual), or fail (error)",
        "type": "string",
        "enum": [
          "follow",
          "manual",
          "error"
        ]
      },
      "maxRedirects": {
        "description": "The most redirects that the call follows (default: 5)",
        "type": "integer",
        "minimum": 0,
        "maximum": 20
      }
    },
    "required": [
      "url"
    ]
  },
  "output": {
    "type": "object",
    "properties": {
      "status": {
        "type": "integer",
        "minimum": -9007199254740991,
        "maximum": 9007199254740991,
        "description": "The status of the response"
      },
      "statusText": {
        "type": "string",
        "description": "The reason phrase of the status"
      },
      "ok": {
        "type": "boolean",
        "description": "True for a status in 200 to 299"
      },
      "url": {
        "type": "string",
        "description": "The URL of the response: the last URL after the redirects"
      },
      "redirected": {
        "type": "boolean",
        "description": "True when the call followed a redirect"
      },
      "headers": {
        "type": "object",
        "propertyNames": {
          "type": "string"
        },
        "additionalProperties": {
          "anyOf": [
            {
              "type": "string"
            },
            {
              "type": "array",
              "items": {
                "type": "string"
              }
            }
          ]
        },
        "description": "The headers of the response, with names in lowercase"
      },
      "body": {
        "description": "The body: text, parsed JSON (null when empty), or bytes in base64"
      },
      "bytes": {
        "type": "integer",
        "minimum": -9007199254740991,
        "maximum": 9007199254740991,
        "description": "The size of the body in bytes, after the content encoding"
      }
    },
    "required": [
      "status",
      "statusText",
      "ok",
      "url",
      "redirected",
      "headers",
      "body",
      "bytes"
    ],
    "additionalProperties": false
  }
}