CrudApiPlugin: Add getRandom action type
- Lingua principale
- C#
- Stelle
- 832
- Fork
- 89
- Merge medio
- 12h 1m
- PR unite (30g)
- 23
Descrizione
## Description
When simulating APIs with CrudApiPlugin, there's currently no way to return a random item from the data store. This is a common API pattern (e.g. `GET /jokes/random`) that can't be replicated with the existing action types.
## Proposed solution
Add a `getRandom` action type that picks a random item from the data file and returns it as a single object.
### Example configuration
```json
{
"action": "getRandom",
"url": "/random"
}
```
### Expected behavior
`GET /baseUrl/random` returns a single random item from the data file, e.g.:
```json
{
"id": 42,
"setup": "Why did the MVP cross the road?",
"punchline": "To screenshot the chicken for LinkedIn."
}
```
## Use case
Simulating the [MVP Jokes API](https://github.com/laskewitz/mvp-jokes-api) which has a `GET /jokes/random` endpoint. Currently, there's no way to mock this with CrudApiPlugin — the closest workaround is `getAll` which returns all items instead of a random one.
Guida per i contributori
Apri la guida per i contributori
Valutazione
Questa issue non è ancora stata valutata.