0.1.1 • Published 3 years ago

bd4bs-fnetwork-layer v0.1.1

Weekly downloads
-
License
MIT
Repository
-
Last release
3 years ago

bd4bs-network-layer-fend

How it works?

That package will help us to have the control of each API Request, taking the control around all the steps needed to send an API Request directly to the customer.


It works using the architecture CLIENT-REQUESTS, bringing the posibility to perform a lot of API Request per each client, here you will need to create a client and send directly the request to the server. Actually it only allows HTTP requests.

Example


First you need to create your ENV file to storage all the statics url securely.

BASE_URL=https://yourowndominan.xyz

Define all the resource-paths you need to query on.

enum API {
 GET = '/get-request'
}
// Create your client
const client = new APIClient(proccess.env.BASEURL);

You need to use Dependency Injection to pass this object to the piece which needs to perform the request, for example, if you are using FLUX-ARCHITECTURE you will need to pass directly to the actions and set the request on that file, let's go to see an example about GET request.

Define the type which should be return once the Fetch has been completed.

type APIResponse = {
  userId: number,
  id: number,
  title: string,
  completed: boolean,
};
// * Only with TS
import {client} from 'where/your/client/is';

// Set request
const request = new APIRequest<APIResponse[]>("/todos", () => {
  return { "Accept": "application/json" }
}, () => []);

client.send(request, (err?: Error, dom?: APIResponse[]) => {
  if (err) {
    console.error(err)
    return;
  }
  // TODO: Perform whatever task you need with DOM object
});

When you create your request, you can pass diferent parameters to configure your own request using differents HTTP Requests.

Diagram


Request->Client: Request object
Note right of Client: Perform the request \n internally
Request-->Client: Waiting to the \n response ...
Client->>Request: Send object \n (DOM?: T, error?: Error)

Contributing


This project is part of a complete system developed for a final customer, contributing to all these code should be perform opened a PR on the REPO or contacting directly to the dev team.

License


To check the licese please go directly to the LICENSE File

0.1.1

3 years ago

0.1.0

3 years ago

0.0.9

3 years ago

0.0.8

3 years ago

0.0.7

3 years ago

0.0.6

3 years ago

0.0.5

3 years ago

0.0.4

3 years ago

0.0.3

3 years ago

0.0.2

3 years ago

0.0.1

3 years ago