Skip to content

Commit

Permalink
docs: Add doc about creating new endpoints
Browse files Browse the repository at this point in the history
  • Loading branch information
AngelOnFira committed Apr 18, 2024
1 parent 3b8aef7 commit 28b2703
Showing 1 changed file with 72 additions and 0 deletions.
72 changes: 72 additions & 0 deletions docs/getting_started/ADDING_AN_ENDPOINT.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,72 @@
# Adding a new endpoint

## Adding a new endpoint to Rivet Core

1. Update the respective `__package.yml__` file with the new endpoint you want
to add. This may require adding something to the `common.yml` file that
should be at `../common.yml` relative to the package file.

2. Run the script `./scripts/fern/gen.sh`. Currently that might look something
like:

`FERN_REPO_PATH=/home/forest/data/git/fern ./scripts/fern/gen.sh`

This will generate new files in `sdks/`. We'll mostly care about the new Rust
files in `sdks/rust/full/rust/src/...`.

3. If you added any enums to the `common.yml` file, you'll need to add/update the
impls in `lib/convert/src/impls`. This allows enums to be mapped from the
generated API type to an internal mapping. For example, in
`lib/convert/src/impls/admin.rs`:

```rust
impl ApiFrom<models::AdminProvider> for backend::cluster::Provider {
fn api_from(value: models::AdminProvider) -> backend::cluster::Provider {
match value {
models::AdminProvider::Linode => backend::cluster::Provider::Linode,
}
}
}
```

4. Add the api endpoint in the related route file for the api. Say
`svc/api/admin/src/route/mod.rs`:

```rust
define_router! {
routes: {
"cluster" / "create": {
POST: cluster::create(
body: models::AdminClusterCreateRequest,
),
},
},
}
```

5. Create the handler for the new endpoint in the related handler file. Say
`svc/api/admin/src/handler/cluster.rs`:

```rust
pub async fn create(
ctx: Ctx<Auth>,
body: models::AdminClusterCreateRequest,
) -> GlobalResult<models::AdminClusterCreateResponse> {
// Your handler code here
}
```

Some tips for this:

- Mapping from an enum in the model to an integer in the protobuf-generated
model can be done with `as i32` (or conversely `from_i32`)


## Connecting to the endpoint with Bolt

If Bolt needs a new CLI command that will interface with this api, these are the
steps you'll need to take:

1. Add the new command to the respective existing or new bolt command.

2.

0 comments on commit 28b2703

Please sign in to comment.