apis-management
v1.0.13
Published
## Introduction apis management is a tool to manage APIs, There are two main purposes of this tool: 1. To document your APIs to make it easy to the your backend developers to understand how to implement the APIs. 2. To call your APIs in one line of code
Downloads
65
Readme
apis management
Introduction
apis management is a tool to manage APIs, There are two main purposes of this tool:
- To document your APIs to make it easy to the your backend developers to understand how to implement the APIs.
- To call your APIs in one line of code
Usage
Installation
npm install apis-managementSetting your APIs
import type { ApiRequest } from "apis-management";
export const apis = [
// Here your APIs
] as const satisfies ReadonlyArray<ApiRequest>;Calling your APIs
import { apiCall } from "apis-management";
const example = await apiCall(apis,apiName, apiParams, apiBody, apiHeaders);
example.// here your API responseExplanation
apis
This is an array of API requests. Each API request should be defined as an object with the following properties:
| Property | Type | Description |
|-----------------------|----------------------------------|------------------------------------------------------------------------------------------------------------------------------------------------------------------------------|
| name | string | The name of the API request. The name only for the API call |
| description | string | A brief description of the API request. |
| url | string | The URL of the API endpoint without the domain. It should start with /. |
| status | boolean | this property can be very confusing, it is used to enable or disable the API request. If the API request is disabled, not status like 404 or 500, it will not be called. |
| params | Record<string, string> \| null | An object containing the query parameters for the API request. If there are no query parameters, it should be null by default. |
| body | Record<string, any> \| null | An object containing the body of the API request. If there is no body, it should be null by default. |
| headers | Record<string, string> \| null | An object containing the headers for the API request. If there are no headers, it should be null by default. |
| method | string | The HTTP method for the API request (e.g., GET, POST, PUT, DELETE). |
| goodResponse | object | An object contaninig the response if the API sucsessful |
| errorResponse | object | An object contaninig the response if the API failed |
| goodResponseStatus | number | The HTTP status code for a successful response. |
| errorResponseStatus | number | The HTTP status code for an error response. |
| comment | string | A comment for the API request. This is optional and can be used to provide additional information about the API request. |
apiCall
This function is used to call an API request from the apis array. It takes the following parameters:
| Parameter | Type | Description |
|--------------|----------------------------------------|--------------------------------------------------------------------------------------------------|
| apis | ReadonlyArray<ApiRequest> | The array of API requests. |
| apiName | string | The name of the API request to call. |
| apiParams | Record<string, string> \| null | An object containing the query parameters for the API request. If there are none, use null. |
| apiBody | Record<string, any> \| null | An object containing the body of the API request. If there is none, use null. |
| apiHeaders | Record<string, string> \| null | An object containing the headers for the API request. If there are none, use null. |
Example
import { apiCall } from "apis-management";
import type { ApiRequest } from "apis-management";
const apis = [
{
name: "getUser",
description: "Get user by id",
url: "/users/:id",
status: true,
params: { id: "123" },
body: null,
headers: null,
method: "GET",
goodResponse: { id: "123", name: "John Doe" },
errorResponse: { error: "User not found" },
goodResponseStatus: 200,
errorResponseStatus: 404,
comment: "This API gets a user by id"
}
] as const satisfies ReadonlyArray<ApiRequest>;
const example = await apiCall(apis, "getUser", { id: "123" }, null, null);
Tasks server component
this is a component that show the tasks.
if you call the TasksServer component, it will show toggle button, when you click on it, it will show the tasks that you defined in the apis array. if you click again, it will hide the tasks.
import { TasksServer } from "apis-management";
import apis from "./apis";
import 'apis-management/dist/tasksServer.css'
export default function App() {
return (
<div>
<TasksServer apis={apis} />
</div>
);
}Created with ❤️ by Yehonatan Refael Cohen. Feel free to contribute or give a ⭐️.
