Skip to content

Commit

Permalink
fix: Document free endpoint defintion placement. (#225)
Browse files Browse the repository at this point in the history
  • Loading branch information
SandPod authored Dec 13, 2024
1 parent bed76d0 commit 0fbb8be
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 2 deletions.
2 changes: 1 addition & 1 deletion docs/01-get-started.md
Original file line number Diff line number Diff line change
Expand Up @@ -121,7 +121,7 @@ At first glance, the complexity of the server may seem daunting, but there are o
These are the most important directories:

- `config`: These are the configuration files for your Serverpod. These include a `password.yaml` file with your passwords and configurations for running your server in development, staging, and production. By default, everything is correctly configured to run your server locally.
- `lib/src/endpoints`: This is where you place your server's endpoints. When you add methods to an endpoint, Serverpod will generate the corresponding methods in your client.
- `lib/src/endpoints`: This is the default location for your server's endpoints. When you add methods to an endpoint, Serverpod will generate the corresponding methods in your client.
- `lib/src/models`: The model definition files are placed here. The files define the classes you can pass through your API and how they relate to your database. Serverpod generates serializable objects from the model definitions.

Both the `endpoints` and `models` directories contain sample files that give a quick idea of how they work. So this a great place to start learning.
Expand Down
20 changes: 19 additions & 1 deletion docs/06-concepts/01-working-with-endpoints.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
# Working with endpoints

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 your endpoint in the endpoints 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.
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.

```dart
import 'package:serverpod/serverpod.dart';
Expand Down Expand Up @@ -72,3 +72,21 @@ maxRequestSize: 1048576
## Return types
The return type must be a typed Future. Supported return types are the same as for parameters.
## Ignore endpoint definition
If you want the code generator to ignore an endpoint definition, you can annotate the class with `@ignoreEndpoint`, imported from `serverpod_shared/annotations.dart`. This can be useful if you want to keep the definition in your codebase without generating server or client bindings for it.

```dart
import 'package:serverpod/serverpod.dart';
import 'package:serverpod_shared/annotations.dart';
@ignoreEndpoint
class ExampleEndpoint extends Endpoint {
Future<String> hello(Session session, String name) async {
return 'Hello $name';
}
}
```

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

0 comments on commit 0fbb8be

Please sign in to comment.