Basics

Guides

API Reference

Menu

Basics

Guides

API Reference

class: HttpServer

[81:14] (extern: com.lehman.aussom.stdlib.AussomHttpServer) extends: object

Methods

  • HttpServer (int Port = 8080)

    Creates and binds the HTTP server to the given port.

    • @p Port is an int with the port number to listen on. Defaults to 8080.
  • newHttpServer (int Port)

  • serveFiles (string UriPath, string LocalDir)

    Registers a static file handler that serves files from a local directory.

    • @p UriPath is a string with the URI path prefix (e.g. "/").
    • @p LocalDir is a string with the local directory path to serve files from.
    • @r this object
  • addHandler (string UriPath, callback Handler)

    Registers a custom callback handler for the given URI path prefix. The callback receives a request map { method, uri, path, query, headers, body } and must return a response map { code, headers, body }.

    • @p UriPath is a string with the URI path prefix (e.g. "/api/").
    • @p Handler is a callback that handles the request.
    • @r this object
  • removeContext (string UriPath)

    Removes a previously registered context by URI path.

    • @p UriPath is a string with the URI path prefix to remove.
    • @r this object
  • start ()

    Starts the server in a background thread (non-blocking).

    • @r this object
  • stop (int DelaySeconds = 1)

    Stops the server, waiting up to DelaySeconds for active exchanges to finish.

    • @p DelaySeconds is an int with max seconds to wait. Defaults to 1.
    • @r this object
  • getPort ()

    Returns the port number the server is bound to.

    • @r An int with the bound port number.

class: http

[8:14] (extern: com.lehman.aussom.stdlib.AussomHttp) extends: object

Http class implements basic HTTP requests.

Methods

  • setTrustAllCerts (bool TrustAllCerts)

    Sets the trust all certs flag and resets the HTTP client. Setting to true isn't recommended for production environments.

    • @p TrustAllCerts is a bool with true to trust all certificates and false to not.
    • @r this object
  • get (string Url, map Headers = null)

    Makes a HTTP GET request to the provided Url and returns a response object.

    • @p Url is a string with the URL to request.
    • @p Headers is an optional map of request headers to set on the call (e.g. { "X-API-KEY": "abc123" }). Values may be strings or lists of strings; lists become repeated headers.
    • @r A HTTP response object.
  • post (string Url, string Content, string MediaType = "application/json; charset=utf-8", map Headers = null)

    Makes a HTTP POST request with the provided arguments.

    • @p Url is a string with the URL to request.
    • @p Content is a string with the POST body content.
    • @p MediaType is a string with the media type. It defaults to application/json and charset utf-8.
    • @p Headers is an optional map of request headers to set on the call. Values may be strings or lists of strings; lists become repeated headers.
    • @r A HTTP response object.
  • put (string Url, string Content, string MediaType = "application/json; charset=utf-8", map Headers = null)

    Makes a HTTP PUT request with the provided arguments.

    • @p Url is a string with the URL to request.
    • @p Content is a string with the PUT body content.
    • @p MediaType is a string with the media type. It defaults to application/json and charset utf-8.
    • @p Headers is an optional map of request headers to set on the call. Values may be strings or lists of strings; lists become repeated headers.
    • @r A HTTP response object.
  • patch (string Url, string Content, string MediaType = "application/json; charset=utf-8", map Headers = null)

    Makes a HTTP PATCH request with the provided arguments.

    • @p Url is a string with the URL to request.
    • @p Content is a string with the PATCH body content.
    • @p MediaType is a string with the media type. It defaults to application/json and charset utf-8.
    • @p Headers is an optional map of request headers to set on the call. Values may be strings or lists of strings; lists become repeated headers.
    • @r A HTTP response object.
  • delete (string Url, map Headers = null)

    Makes a HTTP DELETE request to the provided Url and returns a response object.

    • @p Url is a string with the URL to request.
    • @p Headers is an optional map of request headers to set on the call. Values may be strings or lists of strings; lists become repeated headers.
    • @r A HTTP response object.