Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

@atproto/xrpc

Package Overview
Dependencies
Maintainers
4
Versions
23
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

@atproto/xrpc

atproto HTTP API (XRPC) client library

  • 0.3.3
  • Source
  • npm
  • Socket score

Version published
Weekly downloads
28K
increased by29.64%
Maintainers
4
Weekly downloads
 
Created
Source

@atproto/xrpc: atproto HTTP API Client

TypeScript client library for talking to atproto services, with Lexicon schema validation.

NPM Github CI Status

Usage

import xrpc from '@atproto/xrpc'

xrpc.addLexicon({
  lexicon: 1,
  id: 'io.example.ping',
  defs: {
    main: {
      type: 'query',
      description: 'Ping the server',
      parameters: {
        type: 'params',
        properties: { message: { type: 'string' } },
      },
      output: {
        encoding: 'application/json',
        schema: {
          type: 'object',
          required: ['message'],
          properties: { message: { type: 'string' } },
        },
      },
    },
  },
})

const res1 = await xrpc.call('https://example.com', 'io.example.ping', {
  message: 'hello world',
})
res1.encoding // => 'application/json'
res1.body // => {message: 'hello world'}
const res2 = await xrpc
  .service('https://example.com')
  .call('io.example.ping', { message: 'hello world' })
res2.encoding // => 'application/json'
res2.body // => {message: 'hello world'}

xrpc.addLexicon({
  lexicon: 1,
  id: 'io.example.writeJsonFile',
  defs: {
    main: {
      type: 'procedure',
      description: 'Write a JSON file',
      parameters: {
        type: 'params',
        properties: { fileName: { type: 'string' } },
      },
      input: {
        encoding: 'application/json',
      },
    },
  },
})

const res3 = await xrpc.service('https://example.com').call(
  'io.example.writeJsonFile',
  { fileName: 'foo.json' }, // query parameters
  { hello: 'world', thisIs: 'the file to write' }, // input body
)

License

MIT

Keywords

FAQs

Package last updated on 27 Oct 2023

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

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc