http-mel 0.10.0

Mélodium HTTP library
use root/method::HttpMethod
use root/method::|delete
use root/method::|get
use root/method::|head
use root/method::|options
use root/method::|patch
use root/method::|post
use root/method::|put
use root/method::|trace
use root/client::HttpClient
use root/status::HttpStatus
use std/data/string_map::StringMap
use root/client::request
use root/client::requestWithBody

/** Performs HTTP DELETE operation.

    Request starts as soon as the URL and headers are transmitted.

    Inputs:

    - `url`: input gives the URL to call DELETE on (combined with optional base from the client model).
    - `headers`: headers to send in request.

    Outputs:

    - `status`: HTTP status response.
    - `headers`: headers received in response.
    - `data`: data received as response, corresponding to the HTTP body.
    - `completed`: emitted when the request finished successfully.
    - `failed`: emitted if the request failed technically.
    - `error`: message containing error when request failed technically.
    - `finished`: emitted when the request finished, regardless of state.
    
    Also see [MDN documentation](https://developer.mozilla.org/docs/Web/HTTP/Methods/DELETE).
*/
treatment delete[client: HttpClient]()
  input url: Block<string>
  input headers: Block<StringMap>
  output data: Stream<byte>
  output headers: Block<StringMap>
  output completed: Block<void>
  output failed: Block<void>
  output finished: Block<void>
  output error: Block<string>
  output status: Block<HttpStatus>
{
    request[client=client](method=|delete())

    Self.url --------> request.url
    Self.headers ----> request.req_headers

    request.data --------> Self.data
    request.res_headers -> Self.headers
    request.completed ---> Self.completed
    request.failed ------> Self.failed
    request.finished ----> Self.finished
    request.error -------> Self.error
    request.status ------> Self.status
}

/** Performs HTTP GET operation.

  Request starts as soon as the URL and headers are transmitted.

    Inputs:

    - `url`: input gives the URL to call GET on (combined with optional base from the client model).
    - `headers`: headers to send in request.
    
    Outputs:

    - `status`: HTTP status response.
    - `headers`: headers received in response.
    - `data`: data received as response, corresponding to the HTTP body.
    - `completed`: emitted when the request finished successfully.
    - `failed`: emitted if the request failed technically.
    - `error`: message containing error when request failed technically.
    - `finished`: emitted when the request finished, regardless of state.
    
    Also see [MDN documentation](https://developer.mozilla.org/docs/Web/HTTP/Methods/GET).
*/
treatment get[client: HttpClient]()
  input url: Block<string>
  input headers: Block<StringMap>
  output data: Stream<byte>
  output headers: Block<StringMap>
  output completed: Block<void>
  output failed: Block<void>
  output finished: Block<void>
  output error: Block<string>
  output status: Block<HttpStatus>
{
    request[client=client](method=|get())

    Self.url --------> request.url
    Self.headers ----> request.req_headers

    request.data --------> Self.data
    request.res_headers -> Self.headers
    request.completed ---> Self.completed
    request.failed ------> Self.failed
    request.finished ----> Self.finished
    request.error -------> Self.error
    request.status ------> Self.status
}

/** Performs HTTP HEAD operation.

    Request starts as soon as the URL and headers are transmitted.

    Inputs:

    - `url`: input gives the URL to call HEAD on (combined with optional base from the client model).
    - `headers`: headers to send in request.
    
    Outputs:

    - `status`: HTTP status response.
    - `headers`: headers received in response.
    - `completed`: emitted when the request finished successfully.
    - `failed`: emitted if the request failed technically.
    - `error`: message containing error when request failed technically.
    - `finished`: emitted when the request finished, regardless of state.
    
    Also see [MDN documentation](https://developer.mozilla.org/docs/Web/HTTP/Methods/HEAD).
*/
treatment head[client: HttpClient]()
  input url: Block<string>
  input headers: Block<StringMap>
  output headers: Block<StringMap>
  output completed: Block<void>
  output failed: Block<void>
  output finished: Block<void>
  output error: Block<string>
  output status: Block<HttpStatus>
{
    request[client=client](method=|head())

    Self.url --------> request.url
    Self.headers ----> request.req_headers

    request.res_headers -> Self.headers
    request.completed ---> Self.completed
    request.failed ------> Self.failed
    request.finished ----> Self.finished
    request.error -------> Self.error
    request.status ------> Self.status
}

/** Performs HTTP OPTIONS operation.

    Request starts as soon as the URL and headers are transmitted.

    Inputs:

    - `url`: input gives the URL to call OPTIONS on (combined with optional base from the client model).
    - `headers`: headers to send in request.
    
    Outputs:

    - `status`: HTTP status response.
    - `headers`: headers received in response.
    - `data`: data received as response, corresponding to the HTTP body.
    - `completed`: emitted when the request finished successfully.
    - `failed`: emitted if the request failed technically.
    - `error`: message containing error when request failed technically.
    - `finished`: emitted when the request finished, regardless of state.
    
    Also see [MDN documentation](https://developer.mozilla.org/docs/Web/HTTP/Methods/OPTIONS).
*/
treatment options[client: HttpClient]()
  input url: Block<string>
  input headers: Block<StringMap>
  output data: Stream<byte>
  output headers: Block<StringMap>
  output completed: Block<void>
  output failed: Block<void>
  output finished: Block<void>
  output error: Block<string>
  output status: Block<HttpStatus>
{
    request[client=client](method=|options())

    Self.url --------> request.url
    Self.headers ----> request.req_headers

    request.data --------> Self.data
    request.res_headers -> Self.headers
    request.completed ---> Self.completed
    request.failed ------> Self.failed
    request.finished ----> Self.finished
    request.error -------> Self.error
    request.status ------> Self.status
}

/** Performs HTTP PATCH operation.

    Request starts as soon as the URL and headers are transmitted.

    Inputs:

    - `url`: input gives the URL to call PATCH on (combined with optional base from the client model).
    - `headers`: headers to send in request.
    - `data`: data sent in request, corresponding to the HTTP body.

    Outputs:

    - `status`: HTTP status response.
    - `headers`: headers received in response.
    - `completed`: emitted when the request finished successfully.
    - `failed`: emitted if the request failed technically.
    - `error`: message containing error when request failed technically.
    - `finished`: emitted when the request finished, regardless of state.
    
    Also see [MDN documentation](https://developer.mozilla.org/docs/Web/HTTP/Methods/PATCH).
*/
treatment patch[client: HttpClient]()
  input url: Block<string>
  input headers: Block<StringMap>
  input data: Stream<byte>
  output headers: Block<StringMap>
  output completed: Block<void>
  output failed: Block<void>
  output finished: Block<void>
  output error: Block<string>
  output status: Block<HttpStatus>
{
    request: requestWithBody[client=client](method=|patch())

    Self.url --------> request.url
    Self.headers ----> request.req_headers
    Self.data -------> request.body

    request.res_headers -> Self.headers
    request.completed ---> Self.completed
    request.failed ------> Self.failed
    request.finished ----> Self.finished
    request.error -------> Self.error
    request.status ------> Self.status
}

/** Performs HTTP POST operation.

    Request starts as soon as the URL and headers are transmitted.

    Inputs:

    - `url`: input gives the URL to call POST on (combined with optional base from the client model).
    - `headers`: headers to send in request.
    - `data`: data sent in request, corresponding to the HTTP body.

    Outputs:

    - `status`: HTTP status response.
    - `headers`: headers received in response.
    - `data`: data received as response, corresponding to the HTTP body.
    - `completed`: emitted when the request finished successfully.
    - `failed`: emitted if the request failed technically.
    - `error`: message containing error when request failed technically.
    - `finished`: emitted when the request finished, regardless of state.
    
    Also see [MDN documentation](https://developer.mozilla.org/docs/Web/HTTP/Methods/POST).
*/
treatment post[client: HttpClient]()
  input url: Block<string>
  input headers: Block<StringMap>
  input data: Stream<byte>
  output data: Stream<byte>
  output headers: Block<StringMap>
  output completed: Block<void>
  output failed: Block<void>
  output finished: Block<void>
  output error: Block<string>
  output status: Block<HttpStatus>
{
    request: requestWithBody[client=client](method=|post())

    Self.url --------> request.url
    Self.headers ----> request.req_headers
    Self.data -------> request.body

    request.data --------> Self.data
    request.res_headers -> Self.headers
    request.completed ---> Self.completed
    request.failed ------> Self.failed
    request.finished ----> Self.finished
    request.error -------> Self.error
    request.status ------> Self.status
}

/** Performs HTTP PUT operation.

    Request starts as soon as the URL and headers are transmitted.

    Inputs:

    - `url`: input gives the URL to call PUT on (combined with optional base from the client model).
    - `headers`: headers to send in request.
    - `data`: data sent in request, corresponding to the HTTP body.

    Outputs:

    - `status`: HTTP status response.
    - `headers`: headers received in response.
    - `completed`: emitted when the request finished successfully.
    - `failed`: emitted if the request failed technically.
    - `error`: message containing error when request failed technically.
    - `finished`: emitted when the request finished, regardless of state.
    
    Also see [MDN documentation](https://developer.mozilla.org/docs/Web/HTTP/Methods/PUT).
*/
treatment put[client: HttpClient]()
  input url: Block<string>
  input headers: Block<StringMap>
  input data: Stream<byte>
  output headers: Block<StringMap>
  output completed: Block<void>
  output failed: Block<void>
  output finished: Block<void>
  output error: Block<string>
  output status: Block<HttpStatus>
{
    request: requestWithBody[client=client](method=|put())

    Self.url --------> request.url
    Self.headers ----> request.req_headers
    Self.data -------> request.body

    request.res_headers -> Self.headers
    request.completed ---> Self.completed
    request.failed ------> Self.failed
    request.finished ----> Self.finished
    request.error -------> Self.error
    request.status ------> Self.status
}

/** Performs HTTP TRACE operation.

    Request starts as soon as the URL and headers are transmitted.

    Inputs:

    - `url`: input gives the URL to call TRACE on (combined with optional base from the client model).
    - `headers`: headers to send in request.

    Outputs:

    - `status`: HTTP status response.
    - `headers`: headers received in response.
    - `completed`: emitted when the request finished successfully.
    - `failed`: emitted if the request failed technically.
    - `error`: message containing error when request failed technically.
    - `finished`: emitted when the request finished, regardless of state.
    
    Also see [MDN documentation](https://developer.mozilla.org/docs/Web/HTTP/Methods/TRACE).
*/
treatment trace[client: HttpClient]()
  input url: Block<string>
  input headers: Block<StringMap>
  output headers: Block<StringMap>
  output completed: Block<void>
  output failed: Block<void>
  output finished: Block<void>
  output error: Block<string>
  output status: Block<HttpStatus>
{
    request[client=client](method=|trace())

    Self.url --------> request.url
    Self.headers ----> request.req_headers

    request.res_headers -> Self.headers
    request.completed ---> Self.completed
    request.failed ------> Self.failed
    request.finished ----> Self.finished
    request.error -------> Self.error
    request.status ------> Self.status
}