# Exercise: Create a CRUD Service

This exercise extends the existing **Train CRUD** runner with a new state. The result is a new CRUD endpoint under the runner. The endpoint reads and writes to a MongoDB collection automatically.

### Before you start

* You can access the **Devops** app.
* The training deployment is installed and `train_crud` is running.
* You know your API base URL: `https://[YOUR_ADMIN_API_DOMAIN]`.

### What you’ll build

* A new state with alias `test`.
* A new endpoint: `https://[YOUR_ADMIN_API_DOMAIN]/api/request/train_crud/test`

{% stepper %}
{% step %}

### Open the Runner screen

Open the [Runner](https://docs.rierino.com/devops/microservices/runners) screen from the [Devops](https://docs.rierino.com/devops) app.

Unless you changed routing, the UI is at `https://[YOUR_ADMIN_UI_DOMAIN]/app/devops/common/runner`.

<figure><img src="https://1659095931-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FcnDk3J1AzTgg2NFrGPlh%2Fuploads%2FsmTD2MvdYEv7DHyvruoq%2Fimage.png?alt=media&#x26;token=55c11dc3-9436-48ef-a250-8c6a85aa1926" alt=""><figcaption><p>Runner UI</p></figcaption></figure>
{% endstep %}

{% step %}

### Select Train CRUD

In the left runner list, filter and select **Train CRUD**.

<figure><img src="https://1659095931-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FcnDk3J1AzTgg2NFrGPlh%2Fuploads%2FsbnlId6q3fiGqvY4A8FD%2Fimage.png?alt=media&#x26;token=90cb32e8-6c03-45d0-bf16-a4d6128bce5b" alt=""><figcaption><p>Train CRUD Runner</p></figcaption></figure>
{% endstep %}

{% step %}

### Add a new State element

Drag a **State** element (table icon) from the stencil onto the runner diagram.

Select the new element. Click the pencil icon to edit it.

<figure><img src="https://1659095931-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FcnDk3J1AzTgg2NFrGPlh%2Fuploads%2FfcC4JJ8WYQTekRl0vvrb%2Fimage.png?alt=media&#x26;token=f9436357-5685-4bb6-a5a0-4ecefc64f7d1" alt=""><figcaption><p>New State Manager</p></figcaption></figure>
{% endstep %}

{% step %}

### Configure it as Generic Master + alias `test`

In the editor:

* Choose **Generic Master**.
* Set **alias** to `test`.

`Generic Master` creates a simple MongoDB-backed state manager on the `master` database. The **alias** becomes:

* the CRUD URL segment (`/test`)
* the MongoDB collection name (`test`)

This is the simplest “new CRUD resource” configuration. For advanced options, use the Devops docs referenced from the CRUD runner section.
{% endstep %}

{% step %}

### Wait for rebuild and test the endpoint

The training Train CRUD runner is typically configured to rebuild every \~30 seconds. After you save, give it a moment to apply the new state.

Then call:

`https://[YOUR_ADMIN_API_DOMAIN]/api/request/train_crud/test`

Expected result:

* HTTP `200 OK`
* Body: `{list: []}` (the collection starts empty)

Full list of supported CRUD operations and parameters is in [CRUD event runner](https://docs.rierino.com/devops/microservices/runners/deploying-runners/spring-runners#crud-event-runner).
{% endstep %}
{% endstepper %}

### Troubleshooting

* **404 Not Found**: confirm the alias is `test` and that you saved the runner. Then wait for the rebuild interval.
* **500 errors**: `Generic Master` points to a MongoDB connection. Check the master DB is reachable.
* **Endpoint exists but returns nothing**: verify you are hitting `train_crud` (URL contains `/train_crud/`).
