1.0.12 • Published 2 months ago

@budarin/json-rpc-request v1.0.12

Weekly downloads
-
License
MIT
Repository
github
Last release
2 months ago

json-rpc-request

Request service for executing requests in Json RPC format

Json RPC uses just POST method for processing requests in

Installation

yarn add @budarin/json-rpc-request

Usage

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<Params, Result, ErrorData>({
    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

1.0.12

2 months ago

1.0.11

2 months ago

1.0.10

3 months ago

1.0.9

5 months ago

1.0.8

5 months ago

1.0.7

5 months ago

1.0.6

5 months ago

1.0.5

5 months ago

1.0.4

5 months ago

1.0.3

5 months ago

1.0.2

5 months ago

1.0.1

5 months ago

1.0.0

5 months ago