Skip to content

Commit d60000d

Browse files
committed
docs: Minor clarity edits to endpoint page (#4047)
1 parent 4b1e3c6 commit d60000d

1 file changed

Lines changed: 27 additions & 13 deletions

File tree

docs/06-concepts/01-working-with-endpoints/01-working-with-endpoints.md

Lines changed: 27 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,17 @@ slug: /concepts/working-with-endpoints
44

55
# Working with endpoints
66

7-
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
818

919
```dart
1020
import 'package:serverpod/serverpod.dart';
@@ -18,6 +28,14 @@ class ExampleEndpoint extends Endpoint {
1828

1929
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.
2030

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+
2139
On the client side, you can now call the method by calling:
2240

2341
```dart
@@ -50,17 +68,11 @@ apiServer:
5068
publicScheme: http
5169
```
5270
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-
5971
## Passing parameters
6072
6173
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.
6274

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.
6476

6577
:::warning
6678

@@ -76,12 +88,14 @@ maxRequestSize: 1048576
7688

7789
The return type must be a typed Future. Supported return types are the same as for parameters.
7890

79-
## Ignore endpoint definition
80-
81-
### Ignore an entire `Endpoint` class
91+
## Excluding endpoints from code generation
8292

8393
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.
8494

95+
### Exclude an entire `Endpoint` class
96+
97+
Annotate the class with `@doNotGenerate` to exclude it entirely:
98+
8599
```dart
86100
import 'package:serverpod/serverpod.dart';
87101
@@ -95,9 +109,9 @@ class ExampleEndpoint extends Endpoint {
95109

96110
The above code will not generate any server or client bindings for the example endpoint.
97111

98-
### Ignore individual `Endpoint` methods
112+
### Exclude individual `Endpoint` methods
99113

100-
Alternatively, you can disable single methods by annotation them with `@doNotGenerate`.
114+
Alternatively, you can exclude individual methods by annotating them with `@doNotGenerate`.
101115

102116
```dart
103117
import 'package:serverpod/serverpod.dart';

0 commit comments

Comments
 (0)