You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardexpand all lines: packages/service/README.md
+9-39
Original file line number
Diff line number
Diff line change
@@ -1,18 +1,12 @@
1
1
# Davstack Service
2
2
3
-
Davstack Service is beautifly simple and flexible library for building backend services with TypeScript.
4
-
5
-
The API is heavily inspired by the [tRPC](https://trpc.io/) procedure builder, providing an extremely intuitive and familiar DX.
6
-
7
-
The key difference is that Davstack Service is a **service** builder, not a procedure API builder.
3
+
Davstack Service is simple and flexible library for building backend services with TypeScript.
8
4
9
5
### Why Use Davstack Service?
10
6
11
-
-**Full Reusability**: Services can be called directly from anywhere in your backend, including within other services, without the overhead of unnecessary API calls.
12
-
13
-
-**Flexible & Portable**: Services are lightweight wrappers around typescript functions, so they can be integrated into any backend eg Next.js server components / actions and support broad range of content types (eg files, streams).
14
-
15
-
-**Seamless Integration with tRPC**: Davstack Service is built to complement tRPC. You can easily turn your services into tRPC procedures / routers with 0 boilerplate.
7
+
- 🏠 Simple and familiar syntax - middleware, input and outputs inspired by trpc procedures
8
+
- 🧩 Flexible - Works well with next js server actions as well as trpc
9
+
- ✅ Typescript first - inferred input/output types and middleware
16
10
17
11
### Installation
18
12
@@ -27,6 +21,8 @@ Visit the [DavStack Service Docs](https://davstack.com/service/overview) for mor
27
21
- The service definition replaces tRPC procedures, but the syntax is very similar.
28
22
- Once the service is integrated into tRPC routers, the API is the same as any other tRPC router.
Define your services in a separate file, and export them for use in your backend.
94
+
Define your services with reusable middleware in a separate file, and export them for reuse.
107
95
108
96
```ts
109
97
// lib/service.ts
@@ -136,9 +124,7 @@ export function createServiceCtx() {
136
124
}
137
125
```
138
126
139
-
### Defining a Service
140
-
141
-
Import the public / authed service builders from the service file, and define your services. You can use the `query` or `mutation` methods to define the service function.
127
+
Import the public / authed service builders from the service
142
128
143
129
```ts
144
130
// api/services/some-service.ts
@@ -168,8 +154,6 @@ const getTasks = service()
168
154
});
169
155
```
170
156
171
-
### Using Services
172
-
173
157
### Direct Service Usage
174
158
175
159
Unlike tRPC procedures, services can be called directly from anywhere in your backend, including within other services.
@@ -221,20 +205,6 @@ const appRouter = t.router({
221
205
222
206
NOTE: it is recommended to use the `* as yourServicesName` syntax. Otherwise, ctrl+click on the tRPC client handler will navigate you to the app router file, instead of the specific service definition.
223
207
224
-
# Comparison with tRPC
225
-
226
-
## Similarities
227
-
228
-
The fluent API is heavily inspired by the [tRPC](https://trpc.io/) procedure builder, providing an extremely intuitive and familiar DX.
229
-
230
-
Services still have access to ctx from middleware, use input/output schemas, and outputs can also be inferred from the query/mutation function, just like tRPC.
231
-
232
-
## Differences
233
-
234
-
The key difference is that Davstack Service is a **service** builder, not a procedure API builder.
235
-
236
-
This brings several benefits by decoupling your _service logic_ (eg database read/write operations), from the _transport layer_ (eg REST or tRPC APIs).
237
-
238
208
### Acknowledgements
239
209
240
210
Davstack Store has been heavily inspired by [tRPC](https://trpc.io/), a fantastic library for building type-safe APIs. A big shout-out to the tRPC team for their amazing work.
0 commit comments