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
-**OrmLite**: All application data (faster, simpler, lighter typed ORM)
138
+
-**OrmLite**: All application data (faster, simpler, typed POCO ORM)
137
139
-**Entity Framework Core**: ASP.NET Core Identity tables only (Users, Roles, etc.)
138
140
139
141
Both use the same SQLite database by default (`App_Data/app.db`). Connection string in `appsettings.json`.
@@ -149,7 +151,7 @@ Run `npm run migrate` to execute both.
149
151
1. ASP.NET Core Identity handles user registration/login via Razor Pages at `/Identity/*` routes
150
152
2. ServiceStack AuthFeature integrates with Identity via `IdentityAuth.For<ApplicationUser>()` in [Configure.Auth.cs](MyApp/Configure.Auth.cs)
151
153
3. Custom claims added via `AdditionalUserClaimsPrincipalFactory` and `CustomUserSession`
152
-
4. ServiceStack services use `[ValidateHasRole]` attributes for authorization (see [Bookings.cs](MyApp.ServiceModel/Bookings.cs))
154
+
4. ServiceStack services use `[ValidateIsAuthenticated]` and `[ValidateHasRole]` attributes for authorization (see [Bookings.cs](MyApp.ServiceModel/Bookings.cs))
153
155
154
156
### ServiceStack .NET APIs
155
157
@@ -170,21 +172,21 @@ public class GetBookingResponse
170
172
}
171
173
```
172
174
173
-
The response type of an API should be specified in the `IReturn<Response>` marker interface. APIs which don't have any response should implement `IReturnVoid` instead.
175
+
The response type of an API should be specified in the `IReturn<Response>` marker interface. APIs which don't return a response should implement `IReturnVoid` instead.
174
176
175
-
By convention APIs returning a single result have a `T? Result` property whilst APIs returning multiple results of the same type have a `List<T> Results` property. Otherwise it's encouraged to use intuitive property names for APIs returning results of different types in a flat structured Response DTO for simplicity.
177
+
By convention, APIs return single results in a `T? Result` property, APIs returns multiple results of the same type in a `List<T> Results` property. Otherwise APIs returning results of different types should use intuitive property names in a flat structured Response DTO for simplicity.
176
178
177
-
These Server DTOs are what gets generated in`dtos.ts`.
179
+
These C# Server DTOs are used to generate TypeScript`dtos.ts`.
178
180
179
181
#### Validating APIs
180
182
181
-
Any API Errors are automatically populated in the `ResponseStatus` property including when using [Declarative Validation Attributes](https://docs.servicestack.net/declarative-validation) like `[ValidateGreaterThan]` and `[ValidateNotEmpty]` which validate APIs and returned any structured error responses in `ResponseStatus`.
183
+
Any API Errors are automatically populated in the `ResponseStatus` property, inc. [Declarative Validation Attributes](https://docs.servicestack.net/declarative-validation) like `[ValidateGreaterThan]` and `[ValidateNotEmpty]` which validate APIs and return any error responses in `ResponseStatus`.
182
184
183
185
#### Protecting APIs
184
186
185
187
The Type Validation Attributes below should be used to protect APIs:
186
188
187
-
-`[ValidateIsAuthenticated]` - Authenticated Users only
189
+
-`[ValidateIsAuthenticated]` - Only Authenticated Users
188
190
-`[ValidateIsAdmin]` - Only Admin Users
189
191
-`[ValidateHasRole]` - Only Authenticated Users assigned with the specified role
190
192
-`[ValidateApiKey]` - Only Users with a valid API Key
@@ -200,11 +202,11 @@ public class CreateBooking : ICreateDb<Booking>, IReturn<IdResponse>
200
202
201
203
#### Primary HTTP Method
202
204
203
-
APIs have a primary HTTP Method which if not specified uses HTTP **POST**. Use `IGet`, `IPost`, `IPut`or `IDelete` to change the HTTP Verb except for AutoQuery APIs which have implied verbs for each operation.
205
+
APIs have a primary HTTP Method which if not specified uses HTTP **POST**. Use `IGet`, `IPost`, `IPut`, `IPatch`or `IDelete` to change the HTTP Verb except for AutoQuery APIs which have implied verbs for each CRUD operation.
204
206
205
207
#### API Implementations
206
208
207
-
Implementations of ServiceStack APIs should be added to the `MyApp.ServiceInterface` folder, e.g:
209
+
ServiceStack API implementations should be added to `MyApp.ServiceInterface/`:
208
210
209
211
```csharp
210
212
//MyApp.ServiceInterface/BookingServices.cs
@@ -228,11 +230,12 @@ public class BookingServices(IAutoQueryDb autoquery) : Service
228
230
}
229
231
```
230
232
231
-
APIs can be implemented with **sync** or **async** methods. The return type of an API implementation does not change behavior however it's encouraged to use `object` to encourage
233
+
APIs can be implemented with **sync** or **async** methods using `Any` or its primary HTTP Method e.g. `Get`, `Post`.
234
+
The return type of an API implementation does not change behavior however returning `object` is recommended so its clear the Request DTO `IReturn<Response>` interface defines the APIs Response type and Service Contract.
232
235
233
-
The ServiceStack `Service` base class has convenience properties like `Db` to resolve an Open `IDbConnection` for that API and `base.Request` to resolve the `IRequest` context. All other dependencies required by the API should use a Primary Constructor with constructor injection.
236
+
The ServiceStack `Service` base class has convenience properties like `Db` to resolve an Open `IDbConnection` for that API and `base.Request` to resolve the `IRequest` context. All other dependencies required by the API should use constructor injection in a Primary Constructor.
234
237
235
-
A ServiceStack API typically returns the Response DTO defined in its Request DTO `IReturn<Response>` or an Error but can also return any [custom Return Type](https://docs.servicestack.net/service-return-types) like a raw`string`, `byte[]`, `Stream`, `IStreamWriter`, `HttpResult` and `HttpError`.
238
+
A ServiceStack API typically returns the Response DTO defined in its Request DTO `IReturn<Response>` or an Error but can also return any raw [custom Return Type](https://docs.servicestack.net/service-return-types) like `string`, `byte[]`, `Stream`, `IStreamWriter`, `HttpResult` and `HttpError`.
236
239
237
240
### AutoQuery CRUD Pattern
238
241
@@ -249,12 +252,12 @@ ServiceStack's AutoQuery generates full CRUD APIs from declarative request DTOs.
249
252
250
253
### TypeScript DTO Generation
251
254
252
-
After changing C# DTOs in `MyApp.ServiceModel/`, run:
255
+
After changing C# DTOs in `MyApp.ServiceModel/`, restart the .NET Server then run:
253
256
```bash
254
257
cd MyApp.Client && npm run dtos
255
258
```
256
259
257
-
This calls ServiceStack's `/types/typescript` endpoint and updates `MyApp.Client/src/lib/dtos.ts` with type-safe client DTOs. The Vite dev server auto-reloads.
260
+
This calls ServiceStack's `/types/typescript` endpoint and updates `dtos.ts` with type-safe client DTOs. The Vite dev server auto-reloads.
258
261
259
262
### okai AutoQuery Code Generation
260
263
@@ -357,7 +360,7 @@ AutoQuery also matches on pluralized fields where `Ids` matches `Id` and applies
357
360
const api =client.api(newQueryBookings({ ids:[1,2,3] }))
The `client` is a configured `JsonServiceClient` pointing to `/api` (proxied to .NET backend).
382
385
383
-
All .NET APIs are accessible by Request DTOs which implement a `IReturn<ResponseType>`or a `IReturnVoid` interface which defines the Response of an API, e.g:
386
+
All .NET APIs are accessible by Request DTOs which implement either a `IReturn<ResponseType>` a `IReturnVoid` interface which defines the API Response, e.g:
Inside a React Component use `useClient()` to resolve a Service Client. The `ApiResult` can be used to hold **loading**, **failed** and **successful** API Response states, e.g:
403
+
Inside a React Component use `useClient()` to resolve a Service Client. The `ApiResult` can hold **loading**, **failed** and **successful** API Response states, e.g:
401
404
402
405
```typescript
403
406
typeProps= { value:string }
@@ -439,12 +442,12 @@ if (api.succeeded) {
439
442
}
440
443
```
441
444
442
-
The `apiForm` API can use a HTML Form's FormData for its Request Body together with the APIs **empty Request DTO**, e.g:
445
+
The `apiForm` API can use a HTML Form's FormData for its Request Body together with an APIs **empty Request DTO**, e.g:
443
446
444
447
```typescript
445
448
constsubmit=async (e:React.FormEvent) => {
446
-
const form =e.currentTargetasHTMLFormElement
447
-
const api =awaitclient.apiForm(newCreateContact(), newFormData(form))
449
+
const form =e.currentTargetasHTMLFormElement
450
+
const api =awaitclient.apiForm(newCreateContact(), newFormData(form))
0 commit comments