dotnet / dotnet/dev-proxy

CrudApiPlugin: Add getRandom action type

Open
#1,669 1 comment 0 reactions 0 assignees View on GitHub
needs peer review
Dominant language
C#
Stars
832
Forks
89
Avg merge
12h 1m
Merged PRs (30d)
23

Description

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

Contributor guide

Open the contributing guide

Assessment

This issue has not been assessed yet.

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.