1.4.8 • Published 2 months ago

@cimo/request v1.4.8

Weekly downloads
-
License
MIT
Repository
github
Last release
2 months ago

Request

Request management. Light, fast and secure. Write with native Typescript code and no dependencies is used.

Publish

  1. npm run build
  2. npm login --auth-type=legacy
  3. npm publish --auth-type=legacy --access public

Installation

  1. Link for npm package -> https://www.npmjs.com/package/@cimo/request

Client

  • Index.ts
...

import { Cr } from "@cimo/request";

...

const cr = new Cr("https://localhost");

cr.setRequestInterceptor((config) => {
    //...

    return {
        ...config,
        headers: {
            ...config.headers,
            "Accept-Language": "en,ja;q=0.9"
        }
    };
});

cr.setResponseInterceptor((response) => {
    if (response.ok) {
        // Success
    } else {
        // Fail
    }
});

...

const data = {
    token_api: "1234",
    name: "test",
};

const formData = new FormData();
formData.append("token_api", "1234");
formData.append("name", "test");
// use formData with "multipart/form-data" or in case of file upload, just remove the headers content-type.

cr.post("/test_post",
            {
                headers: {
                    "Content-Type": "application/json"
                }
            },
            data
        )
        .then((data) => {
            // Response
        })
        .catch((error) => {
            // Error
        });

cr.get("/test_get", {})
    .then((data) => {
        // Response
    })
    .catch((error) => {
        // Error
    });

// put, delete, patch

...
1.4.8

2 months ago

1.4.7

3 months ago

1.4.6

3 months ago

1.4.5

5 months ago

1.4.4

6 months ago

1.3.4

6 months ago

1.2.4

7 months ago

1.2.3

7 months ago

1.2.2

7 months ago

1.1.2

7 months ago

1.1.1

7 months ago

1.0.0

7 months ago