CrudApiPlugin: Add getRandom action type

Open
#1,669 1 comment 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

Assessment

Difficulty
3/5
Estimated time
1-2 days
Newbie friendliness
68/100
Issue type
Feature
Clarity
Mostly clear
Activity status
Quiet
Tech stack
csharp
Domain
api, backend

Research direction

Start by locating CrudApiPlugin's action-type handling and the existing getAll path. Add the proposed getRandom configuration behavior, then verify that GET /baseUrl/random returns one item from the data file rather than the full collection.

Written by the indexing model from the issue text.

Description

needs peer review

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
{
  "action": "getRandom",
  "url": "/random"
}
Expected behavior

GET /baseUrl/random returns a single random item from the data file, e.g.:

{
  "id": 42,
  "setup": "Why did the MVP cross the road?",
  "punchline": "To screenshot the chicken for LinkedIn."
}

Use case

Simulating the 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.

Dominant language
C#
Stars
832
Forks
89
Avg merge
13h 17m
Merged PRs (30d)
42

Contributor guide

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

More from dotnet/dev-proxy

All issues in dotnet/dev-proxy

Similar issues

More C# issues

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.