Socket
Book a DemoInstallSign in
Socket

api-to-rpc

Package Overview
Dependencies
Maintainers
1
Versions
14
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

api-to-rpc

0.1.1
latest
npmnpm
Version published
Weekly downloads
73
461.54%
Maintainers
1
Weekly downloads
 
Created
Source

library that using proxy api to implement the rpc client with only the type of the backend endpoints at runtime

npm i --save ofetch api-to-rpc

Example

basic

import rpc from 'api-to-rpc';
type API = {
    users: {
        ':id': {
            query: {
                queryHere: true,
            },
            params: {
                id: 'zzz',
            }
        },
    },
    posts: {},
    sessions: {},
}
const { users } = rpc<API>({
    baseURL: '/api',
    onRequest: (payload, fetcher) => fetcher(payload),
    onResponse: (data) => data,
});
const res = await users[':id'].$query();

form-data

client-side

  formData.append('file', new File([''], 'test.txt', { type: 'text/plain' }));
  const data = await api.$post({ body: formData });

server-side (nitro)

options

rpc({
    transform() {
        
    }
})

SuperJSON

client-side

server-side

TODO

  • formdata
  • [] SSE
  • [] infer type
  • openAPI (nitro)
  • query, body 등에서 props가 전부 optional일 경우 body: {} 를 하지 않아도 문제 없도록
  • then 할 경우 promise가 두 개라 promise가 가져와짐.
  • beforeRequest, beforeResponse

FAQs

Package last updated on 06 Jun 2025

Did you know?

Socket

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts

SocketSocket SOC 2 Logo

Product

About

Packages

Stay in touch

Get open source security insights delivered straight into your inbox.

  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc

U.S. Patent No. 12,346,443 & 12,314,394. Other pending.