# sioapi

> Module for making API requests

Latest version **1.0.2** (published 2021-11-20) · ISC license · 0 weekly downloads

## Install

```sh
npm install sioapi
pnpm add sioapi
yarn add sioapi
bun add sioapi
```

## Health

**Score 20/100 (F)** — status: abandoned.

Positive: esm support; no vulnerabilities.

Warnings: low downloads; no types.

Negative: abandoned; low maintenance score.

## Facts

| | |
|---|---|
| Version | 1.0.2 |
| Published | 2021-11-20 |
| First published | 2021-10-30 |
| Weekly downloads | 0 |
| License | ISC |
| TypeScript types | none |
| Module format | ESM + CommonJS |
| Dependencies | 0 |
| Unpacked size | 25.2 KB |
| Known vulnerabilities | 0 |
| Install scripts | no |
| GitHub stars | 0 |
| Author | SIOrbita |
| Maintainers | empirreamm |
| Keywords | SIO, API, API, client, client |

## Links

- npm: https://www.npmjs.com/package/sioapi
- Repository: https://github.com/empirreamm/SioApi
- Homepage: https://github.com/empirreamm/SioApi#readme
- Issues: https://github.com/empirreamm/SioApi/issues
- npm.io page: https://npm.io/package/sioapi

## Alternatives

- [launchdarkly-js-client-sdk](https://npm.io/package/launchdarkly-js-client-sdk.md) — 2.5M weekly downloads
- [@elastic/elasticsearch](https://npm.io/package/@elastic/elasticsearch.md) — 2.1M weekly downloads
- [@c8y/client](https://npm.io/package/@c8y/client.md) — 15.3K weekly downloads
- [@signaldb/maverickjs](https://npm.io/package/@signaldb/maverickjs.md) — 1.7K weekly downloads
- [@bbc/http-transport-cache](https://npm.io/package/@bbc/http-transport-cache.md) — 1.2K weekly downloads

## Recent versions

- 1.0.2 (latest) — 2021-11-20
- 1.0.1 — 2021-10-30
- 1.0.0 — 2021-10-30

## README

# SioApi
  Navigator module for making API requests and controlling the responses.
## Install

  ```bash
    npm install sioapi
  ```

## Import

  Bundle

```javascript
import SioApi from "sioapi";
```

  CDN

```javascript
import SioApi from "https://unpkg.com/sioapi";
```

## API

Creates a new SioApi Object. 

This module extends [SioEvents](https://github.com/empirreamm/SioEvents).

* ### Constructor: new SioApi(url).
  |Name|Type|Description|
  |---|---|---|
  |url|String|Url of the API, leave blank to use current host.

* ### Events: .on(eventName,callback).
  Check [SioEvents](https://github.com/empirreamm/SioEvents) for more details

  |Event|Fire Time|Data|
  |---|---|---|
  |response|Whenever a response from the server is received|[Call Object](#call)

* ### Methods

  * #### .getService(name).
      Creates a new [Service Object](#service) to the API url/name

  * #### .setHeader(name,value).
      Sets a header to be send to every petition on this api.

  * #### .removeHeader(name).
      Removes a header from the apis
  
  * ### [Async] .get(suburl="",options={}) __or__ .get(options={})
      1. If subUrl is setted makes a GET fetch to [API.url](#api)/subUrl with the options.
      2. If subUrl is not setted makes a GET fetch to [API.url](#api) with the options.
      Returns a [Call Object](#call).

  * ### [Async] .post(suburl="", data={}, options={}) __or__ .post(data={}, options={})
      1. If subUrl is setted makes a POST fetch to [API.url](#api)/subUrl with the options and the body of data.
      2. If subUrl is not setted makes a POST fetch to [API.url](#api) with the options and the body of data.
      Returns a [Call Object](#call).

  * ### [Async] .put(suburl="", data={}, options={}) __or__ .put(data={}, options={})
      1. If subUrl is setted makes a PUT fetch to [API.url](#api)/subUrl with the options and the body of data.
      2. If subUrl is not setted makes a PUT fetch to [API.url](#api) with the options and the body of data.
      Returns a [Call Object](#call).

  * ### [Async] .delete(suburl="", data={}, options={}) __or__ .delete(data={}, options={})
      1. If subUrl is setted makes a DELETE fetch to [API.url](#api)/subUrl with the options and the body of data.
      2. If subUrl is not setted makes a DELETE fetch to [API.url](#api) with the options and the body of data.
      Returns a [Call Object](#call).

## Service
  Created from the call of an [API.getService(name)](#-getservice-name--).
  This is used as a middleware between the apiurl and the service you're trying to fetch.
  Example: 
    If API.url="https://example.com/api"
    A service can be: "users"
  * ### Constructor: new Service(url="",service="",api=null).
    No documentation because this is not intended to be used directly. 
    Call API.getService() instead.
  * ### Events: .on(eventName,callback).
    Check [SioEvents](https://github.com/empirreamm/SioEvents) for more details

    |Event|Fire Time|Data|
    |---|---|---|
    |response|Whenever a response from the server is received|[Call Object](#call)
  * ### Methods

    * #### .getService(name).
        Creates a new [Service Object](#service) to the API url/name

    * #### .setHeader(name,value).
        Sets a header to be send to every petition on this Service.

    * #### .removeHeader(name).
        Removes a header from the Service.

    * ### [Async] .get(suburl="",options={}) __or__ .get(options={})
        This is going to use the headers from the caller API and the headers from the Service.

        1. If subUrl is setted makes a GET fetch to [API.url](#api)/${this.service}/suburl with the options.
        2. If subUrl is not setted makes a GET fetch to [API.url](#api)/${this.service} with the options.

        Returns a [Call Object](#call).

    * ### [Async] .post(suburl="", data={}, options={}) __or__ .post(data={}, options={})
        This is going to use the headers from the caller API and the headers from the Service.

        1. If subUrl is setted makes a POST fetch to [API.url](#api)/${this.service}/subUrl with the options and the body of data.
        2. If subUrl is not setted makes a POST fetch to [API.url](#api)/${this.service} with the options and the body of data.

        Returns a [Call Object](#call).

    * ### [Async] .put(suburl="", data={}, options={}) __or__ .put(data={}, options={})
        This is going to use the headers from the caller API and the headers from the Service.

        1. If subUrl is setted makes a PUT fetch to [API.url](#api)/${this.service}/subUrl with the options and the body of data.
        2. If subUrl is not setted makes a PUT fetch to [API.url](#api)/${this.service} with the options and the body of data.

        Returns a [Call Object](#call).

    * ### [Async] .delete(suburl="", data={}, options={}) __or__ .delete(data={}, options={})
        This is going to use the headers from the caller API and the headers from the Service.

        1. If subUrl is setted makes a DELETE fetch to [API.url](#api)/${this.service}/subUrl with the options and the body of data.
        2. If subUrl is not setted makes a DELETE fetch to [API.url](#api)/${this.service} with the options and the body of data.

        Returns a [Call Object](#call).

## Call
  ### Properties
  |Name|Type|Description|
  |---|---|---|
  |url|String|The url the request was made.
  |headers|Object|Object with the headers of the response.
  |blob|Blob|Blob of the body of the response.
  |response|Response|A Response Object with a clone of the fetch response.
  |status|Number|Number status of the response.
  |ok|String|response.ok
  |statusText|String|response.statusText.
  |raw|Any|The computed raw data of the response.
  |data|Any|The computed prefered type of the response (In case of the response being a json this is an object representation of that JSON).

  ### Events
  
  This fires the events "response" in the [Service](#service) and in the [API](#api) listeners. The listeners can change the final properties of this call.

---
_Source: https://npm.io/package/sioapi · Machine-readable twin of the npm.io package page. Health data is recomputed on every publish._
