dotnet / dotnet/dev-proxy

CrudApiPlugin: Add getRandom action type

Offen
#1,669 1 Kommentar 0 Reaktionen 0 zugewiesene Personen Auf GitHub ansehen
needs peer review
Vorherrschende Sprache
C#
Sterne
832
Forks
89
Ø Merge
12 Std. 1 Min.
Gemergte PRs (30 T.)
23

Beschreibung

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

Beitragsleitfaden

Beitragsleitfaden öffnen

Rechercherichtung

Beginne damit, die Verarbeitung des Action-Typs von CrudApiPlugin und den vorhandenen getAll-Pfad zu lokalisieren. Füge anschließend das vorgeschlagene Konfigurationsverhalten für getRandom hinzu und überprüfe dann, dass GET /baseUrl/random ein Element aus der Datendatei statt der vollständigen Sammlung zurückgibt.

Vom Indexierungsmodell aus dem Issue-Text verfasst.

Bewertung

Tech-Stack
csharp
Bereich
api, backend
Issue-Typ
Feature
Schwierigkeit
3/5
Geschätzter Aufwand
1-2 Tage
Aktivitätsstatus
Ruhig
Klarheit
Größtenteils klar
Anfängerfreundlichkeit
68/100

Neue Issues direkt in Ihr Postfach

Eine kurze Übersicht über anfängerfreundliche GitHub-Issues.