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
Endpoints are the connection points to the server from the client. With Serverpod, you add methods to your endpoint, and your client code will be generated to make the method call. For the code to be generated, you need to place the endpoint file anywhere under the `lib` directory of your server. Your endpoint should extend the `Endpoint` class. For methods to be generated, they need to return a typed `Future`, and its first argument should be a `Session` object. The `Session` object holds information about the call being made and provides access to the database.
7
+
Endpoints define the server methods that the client can call. With Serverpod, you add methods to your endpoint, and your client code will be generated to make the method call.
8
+
9
+
For the client code to be generated:
10
+
11
+
- Place the endpoint file anywhere under the `lib` directory of your server.
12
+
- Create a class that extends `Endpoint`.
13
+
- Define methods that return a typed `Future` and take a `Session` object as their first argument.
14
+
15
+
The `Session` object holds information about the call being made and provides access to the database.
16
+
17
+
## Creating an endpoint
8
18
9
19
```dart
10
20
import 'package:serverpod/serverpod.dart';
@@ -18,6 +28,14 @@ class ExampleEndpoint extends Endpoint {
18
28
19
29
The above code will create an endpoint called `example` (the Endpoint suffix will be removed) with the single `hello` method. To generate the client-side code run `serverpod generate` in the home directory of the server.
20
30
31
+
:::info
32
+
33
+
You can pass the `--watch` flag to `serverpod generate` to watch for changed files and generate code whenever your source files are updated. This is useful during the development of your server.
34
+
35
+
:::
36
+
37
+
## Calling an endpoint
38
+
21
39
On the client side, you can now call the method by calling:
22
40
23
41
```dart
@@ -50,17 +68,11 @@ apiServer:
50
68
publicScheme: http
51
69
```
52
70
53
-
:::info
54
-
55
-
You can pass the `--watch` flag to `serverpod generate` to watch for changed files and generate code whenever your source files are updated. This is useful during the development of your server.
56
-
57
-
:::
58
-
59
71
## Passing parameters
60
72
61
73
There are some limitations to how endpoint methods can be implemented. Parameters and return types can be of type `bool`, `int`, `double`, `String`, `UuidValue`, `Duration`, `DateTime`, `ByteData`, `Uri`, `BigInt`, or generated serializable objects (see next section). A typed `Future` should always be returned. Null safety is supported. When passing a `DateTime` it is always converted to UTC.
62
74
63
-
You can also pass `List`, `Map`, `Record` and `Set` as parameters, but they need to be strictly typed with one of the types mentioned above.
75
+
You can also pass `List`, `Map`, `Record`, and `Set` as parameters, but they need to be strictly typed with one of the types mentioned above.
64
76
65
77
:::warning
66
78
@@ -76,12 +88,14 @@ maxRequestSize: 1048576
76
88
77
89
The return type must be a typed Future. Supported return types are the same as for parameters.
78
90
79
-
## Ignore endpoint definition
80
-
81
-
### Ignore an entire `Endpoint` class
91
+
## Excluding endpoints from code generation
82
92
83
93
If you want the code generator to ignore an endpoint definition, you can annotate either the entire class or individual methods with `@doNotGenerate`. This can be useful if you want to keep the definition in your codebase without generating server or client bindings for it.
84
94
95
+
### Exclude an entire `Endpoint` class
96
+
97
+
Annotate the class with `@doNotGenerate` to exclude it entirely:
98
+
85
99
```dart
86
100
import 'package:serverpod/serverpod.dart';
87
101
@@ -95,9 +109,9 @@ class ExampleEndpoint extends Endpoint {
95
109
96
110
The above code will not generate any server or client bindings for the example endpoint.
97
111
98
-
### Ignore individual `Endpoint` methods
112
+
### Exclude individual `Endpoint` methods
99
113
100
-
Alternatively, you can disable single methods by annotation them with `@doNotGenerate`.
114
+
Alternatively, you can exclude individual methods by annotating them with `@doNotGenerate`.
0 commit comments