Gathering detailed insights and metrics for pathic
Gathering detailed insights and metrics for pathic
Gathering detailed insights and metrics for pathic
Gathering detailed insights and metrics for pathic
Type-safe RPC with generated runtime validation, REST semantics, and json-seq streams
npm install pathic
Module System
Min. Node Version
Typescript Support
Node Version
NPM Version
12 Stars
165 Commits
1 Watching
4 Branches
1 Contributors
Updated on 22 Nov 2024
TypeScript (98.28%)
JavaScript (1.49%)
Shell (0.23%)
Cumulative downloads
Total Downloads
Last day
0%
1
Compared to previous day
Last week
0%
2
Compared to previous week
Last month
441.3%
341
Compared to previous month
Last year
0%
404
Compared to previous year
No dependencies detected.
RPC/REST hybrid middleware for Node.js and Bun. Comes with a type-safe client library, pure-TypeScript request validation, and JSON streaming. Powered by popular open-source libraries, like Ky, TypeBox, and Hattip.
/users/:id
or /foo/*bar
) and efficient route matching via pathicIn the root directory of your project, install the alien-rpc
package:
1pnpm add alien-rpc
This package contains the CLI, code generator, client library, and server library.
In the root directory of your backend, install TypeBox for runtime validation:
1pnpm add @sinclair/typebox
Alien RPC is unopinionated about your project structure, but it's assumed your client code and server code are in separate directories.
[!IMPORTANT] Before you use the code generator, you'll want to get familiar with how to define routes. Give this page a read, then come back here afterwards.
The code generator can be customized with a variety of options. You can use the --help
flag to see all the options available. For now, we'll keep it simple and use only a few.
By default, the code generator assumes you'll run it from the root directory of your project (the one that contains your client
and server
package directories). It will emit route definitions to the client/generated/api.ts
and server/generated/api.ts
files, unless told otherwise via the --clientOutFile
and --serverOutFile
options respectively. Feel free to customize this to match your project structure.
With the --versionPrefix
option, you can prefix every route with an API version.
For example, using --versionPrefix v1
would turn the /foo
route into /v1/foo
. Note that you could use any prefix you want (e.g. a date or a name), not just a version number.
This allows for breaking changes to your API without breaking existing client applications. Currently, you're on the hook for managing and deploying multiple versions of your API's server code, which is necessary during the gradual migration process.
The code generator must be told where to find your routes, which is typically done with a glob pattern. At this point, you should have at least one route defined in your server code. I like to keep my routes in the src/api
directory of my server package, so we'll use that in the following example. Any unflagged arguments will be interpreted as glob patterns, used to search for routes:
1pnpm alien-rpc src/api/**/*.ts \ 2 --clientOutFile client/generated/api.ts \ 3 --serverOutFile server/generated/api.ts \ 4 --versionPrefix v1 \ 5 --watch
The --watch
flag will automatically re-run the code generator when your routes change, including any modules you import from.
When developing your API, you can run your TypeScript code directly with the following command:
1node --watch --experimental-strip-types server/src/main.ts
This assumes you have the latest Node.js version installed.
Once you're ready to deploy your API, you can compile your TypeScript code with a number of different tools. This is currently beyond the scope of this guide.
Please be aware of the following limitations:
Response
object.If you find any other limitations, please open a pull request to update this list.
No vulnerabilities found.
No security vulnerabilities found.