Skip to content

HTTP

Classes

HTTPStreamObservableStream

Functions

http(config)HTTPStream

Sends an HTTP request.

HTTPStream ⇐ ObservableStream

Kind: global class
Extends: ObservableStream

new HTTPStream()

A class that extends ObservableStream and provides additional methods for handling HTTP requests.

HTTPStream.toJson() ⇒ Promise

Converts the response data to JSON.

Kind: static method of HTTPStream
Returns: Promise - A promise that resolves to the JSON data.
Example

http('https://api.example.com/data')
  .toJson()
  .then(data => console.log(data))
  .catch(error => console.error(error));

HTTPStream.on(event, handler) ⇒ HTTPStream

Registers an event handler for a specified event.

Kind: static method of HTTPStream
Returns: HTTPStream - The HTTPStream instance.

Param Type Description
event string The event to register the handler for.
handler function The handler function.

http(config) ⇒ HTTPStream

Sends an HTTP request.

Kind: global function
Returns: HTTPStream - An HTTPStream that resolves to the response data.

Param Type Description
config Object | string The configuration object or URL string.

Example

http('https://api.example.com/data')
  .tap(data => console.log(data))
  .catchError(error => console.error(error));

http.get(url, [config]) ⇒ HTTPStream

Sends a GET request.

Kind: static method of http
Returns: HTTPStream - An HTTPStream that resolves to the response data.

Param Type Default Description
url string The URL to send the GET request to.
[config] Object {} Optional configuration object.

Example

http.get('https://api.example.com/data')
  .tap(data => console.log(data))
  .catchError(error => console.error(error));

http.post(url, [data], [config]) ⇒ HTTPStream

Sends a POST request.

Kind: static method of http
Returns: HTTPStream - An HTTPStream that resolves to the response data.

Param Type Default Description
url string The URL to send the POST request to.
[data] Object {} The data to send in the body of the POST request.
[config] Object {} Optional configuration object.

Example

http.post('https://api.camijs.com/posts', { title: 'foo', body: 'bar', userId: 1 })
  .tap(data => console.log(data))
  .catchError(error => console.error(error));

http.put(url, [data], [config]) ⇒ HTTPStream

Sends a PUT request.

Kind: static method of http
Returns: HTTPStream - An HTTPStream that resolves to the response data.

Param Type Default Description
url string The URL to send the PUT request to.
[data] Object {} The data to send in the body of the PUT request.
[config] Object {} Optional configuration object.

Example

http.put('https://api.camijs.com/posts/1', { id: 1, title: 'foo', body: 'bar', userId: 1 })
  .tap(data => console.log(data))
  .catchError(error => console.error(error));

http.patch(url, [data], [config]) ⇒ HTTPStream

Sends a PATCH request.

Kind: static method of http
Returns: HTTPStream - An HTTPStream that resolves to the response data.

Param Type Default Description
url string The URL to send the PATCH request to.
[data] Object {} The data to send in the body of the PATCH request.
[config] Object {} Optional configuration object.

Example

http.patch('https://api.camijs.com/posts/1', { title: 'foo' })
  .tap(data => console.log(data))
  .catchError(error => console.error(error));

http.delete(url, [config]) ⇒ HTTPStream

Sends a DELETE request.

Kind: static method of http
Returns: HTTPStream - An HTTPStream that resolves to the response data.

Param Type Default Description
url string The URL to send the DELETE request to.
[config] Object {} Optional configuration object.

Example

http.delete('https://api.camijs.com/posts/1')
  .tap(data => console.log(data))
  .catchError(error => console.error(error));

http.sse(url, [config]) ⇒ HTTPStream

Establishes a Server-Sent Events connection.

Kind: static method of http
Returns: HTTPStream - An HTTPStream with methods to register event handlers, handle errors, and close the connection.

Param Type Default Description
url string The URL to establish a Server-Sent Events connection.
[config] Object {} Optional configuration object.

Example

const stream = http.sse('https://api.example.com/events');
stream.on('message', event => console.log(event.data));
stream.catchError(error => console.error(error));