Simplified endpoint listener

[io/http/server/Simplified endpoint listener]

Opinionated version of io/http/server/Endpoint listener. Sets up a listener on an HTTP route, and handles bad request errors. Starts an Express server if one is not started yet. Possible error responses:

  • { "status": 400, "headers": {}, "body": "Bad request" }

  • { "status": 403, "headers": {}, "body": "Unauthorized" }

Keywords: http, server, endpoint, get, post, put, delete, listen, api, opinionated, error handling

Input ports

  • response:

    {"status": number, "headers": {string: string}, "body": string}
  • params:

        "serverId": string,
        "port": number,
        "method": ("GET" or "POST" or "PUT" or "PATCH" or "DELETE"),
        "route": string,
        optional "host": string,
        optional "request": {
          optional "bearerToken": string,
          optional "contentType": ("text" or "json" or "urlencoded")
        optional "response": {optional "contentType": ("text" or "json")}
      and {optional "timeout": number}

Output ports

  • request:

      "baseUrl": string,
      "body": any,
      "cookies": any,
      "hostname": string,
      "headers": {string: string},
      "ip": string,
      "ips": string[],
      "method": ("GET" or "POST" or "PUT" or "PATCH" or "DELETE"),
      "originalUrl": string,
      "params": {string: string},
      "path": string,
      "protocol": ("http" or "https"),
      "query": {string: any},
      "route": string,
      "secure": boolean,
      "signedCookies": any,
      "stale": boolean,
      "subdomains": string[],
      "xhr": boolean

Last updated