An open API service indexing awesome lists of open source software.

https://github.com/budarin/json-rpc-request

Request service for executing requests in Json RPC format
https://github.com/budarin/json-rpc-request

Last synced: 9 months ago
JSON representation

Request service for executing requests in Json RPC format

Awesome Lists containing this project

README

          

# json-rpc-request

Request service for executing requests in Json RPC format

Json RPC uses just POST method for processing requests in

## Installation

```sh
yarn add @budarin/json-rpc-request
```

## Usage

```ts
import { createRequest } from '@budarin/json-rpc-request';

const baseApiUrl = 'http://domain/api';
const apiRequest = createRequest(baseApiUrl);

type Params = {
multiplier: number;
};
type Result = {
your_money: number;
};
type ErrorData = {
your_money: number;
};

const result = await apiRequest({
body: {
id: 1,
method: 'multiply_my_money',
params: {
multiplier: 200,
},
},
headers: {
'Content-Type': 'application/json',
},
});

console.log(result);

// response:
// {
// id: 1,
// result: {
// your_money: 4000000000000000000, 😁
// }
// }
//
// or maybe:
// {
// id: 1,
// error: {
// code: 500,
// message: 'you really want a lot',
// data: {
// your_money: 5,
// },
// }
// }
```

## License

MIT