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
- Host: GitHub
- URL: https://github.com/budarin/json-rpc-request
- Owner: budarin
- License: mit
- Created: 2023-11-29T11:10:48.000Z (about 2 years ago)
- Default Branch: master
- Last Pushed: 2024-10-10T12:08:59.000Z (about 1 year ago)
- Last Synced: 2025-04-02T08:36:44.337Z (9 months ago)
- Language: TypeScript
- Homepage: https://www.npmjs.com/package/@budarin/json-rpc-request
- Size: 28.3 KB
- Stars: 0
- Watchers: 2
- Forks: 0
- Open Issues: 1
-
Metadata Files:
- Readme: README.md
- License: LICENSE
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