pFad - Phone/Frame/Anonymizer/Declutterfier! Saves Data!


--- a PPN by Garber Painting Akron. With Image Size Reduction included!

URL: http://github.com/d3byte/rxjs-http

onymous" media="all" rel="stylesheet" href="https://github.githubassets.com/assets/primer-a33d805aa3bce2cb.css" /> GitHub - d3byte/rxjs-http: Javascript and Typescript HTTP client based on observables · GitHub
Skip to content

d3byte/rxjs-http

Repository files navigation

rxjs-http

Build Status

HTTP client based on observables.

Compatible with both Javascript and Typescript.

Table of Content

Example

import { http } from '@d3byte/rxjs-http';

const configuration = {
    baseUrl: 'http://localhost:8080',
};

const httpClient = http(configuration);

httpClient
    .post(
        'login', 
        { username: 'user', password: 'pass' },
        { MyCustomHeader: 'Value' },
    )
    .subscribe(user => {
        // Do something with data
    });

Available methods

All methods you would probably need are available in the package. You can use all of those:

  • GET
  • POST
  • PUT
  • PATCH
  • DELETE

Configuration

The package supports configuring clients and keeping multiple instances of clients at the same time.

To configure a client, you have to pass a configuration object to http function.

Interfaces

ConfigurationInterface

This interface represents objects for configuring HTTP Client.

interface ConfigurationInterface {
    jwt?: string;
    baseUrl?: string;
    defaultHeaders?: ObjectInterface;
}

Properties:

  • jwt [optional] – property where you can store jwt token for communication with api. Client will automatically insert it into Authorization header with Bearer.
  • baseUrl [optional] – URL to API. For example, http://localhost:8080. Pay attention that there should not be a a slash (/) at the end of the url. If no baseUrl passed, you will have to manually set the entire url in method calls.
  • defaultHeaders [optional] – an object with pairs of keys and strings. Here you can pass any default headers you want. Client will insert them into requests.

ObjectInterface

A simple representation of object with dynamic keys and values. It suits for any object you would ever pass.

Examples of all available methods

GET

httpClient
    .get(
        'user', 
        { MyCustomHeader: 'Value' },
    )
    .subscribe(user => {
        // Do something with data
    });

POST

httpClient
    .post(
        'login', 
        { username: 'user', password: 'pass' },
        { MyCustomHeader: 'Value' },
    )
    .subscribe(user => {
        // Do something with data
    });

PUT

httpClient
    .put(
        'books', 
        { title: 'Fav Book' },
        { MyCustomHeader: 'Value' },
    )
    .subscribe(data => {
        // Do something with data
    });

PATCH

httpClient
    .patch(
        'books', 
        { title: 'Fav Book' },
        { MyCustomHeader: 'Value' },
    )
    .subscribe(data => {
        // Do something with data
    });

DELETE

httpClient
    .delete(
        'books', 
        { title: 'Fav Book' },
        { MyCustomHeader: 'Value' },
    )
    .subscribe(data => {
        // Do something with data
    });

Packages

 
 
 

Contributors

pFad - Phonifier reborn

Pfad - The Proxy pFad © 2024 Your Company Name. All rights reserved.





Check this box to remove all script contents from the fetched content.



Check this box to remove all images from the fetched content.


Check this box to remove all CSS styles from the fetched content.


Check this box to keep images inefficiently compressed and original size.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy