Eric Bailey a7c42cfe39
Clean up prettier/eslint scripts ()
* add prettierignore, hoist script

* upgrade prettier

* bump prettier eslint deps

* format all files

* hoist prettier check

* remove unused scripts, hoist lint:fix

* remove npm-run-all, unused

* hoist lint

* remove lint scripts

* improve lint scripts

* remove prettierignores

* downgrade prettier deps to fix codgen

* reformat all files

* update makefile, format

* fix locklife

* final format

---------

Co-authored-by: dholms <dtholmgren@gmail.com>
2023-09-06 19:27:50 -05:00
..
2023-08-10 13:42:31 -05:00
2023-09-05 18:45:49 -05:00

XRPC API

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