dennisdoomen / dennisdoomen/mockly
[API Proposal]: Import mocks from curl commands
- Dominant language
- C#
- Stars
- 40
- Forks
- 9
- Avg merge
- 2d 1h
- Merged PRs (30d)
- 13
Description
## Background and motivation
Developers often have a working `curl` command copied from browser devtools ("Copy as cURL") or API documentation. Translating it by hand into `ForGet().WithPath(...).WithHeader(...)` chains is tedious. Importing a curl command would bootstrap a realistic mock from real traffic quickly.
This issue is split from #124 and covers the smaller, predictable first phase only.
## API Proposal
```csharp
RequestMockBuilder ImportFromCurl(string curlCommand);
```
The method would be added to `HttpMock` and return a builder so callers can attach a response.
## API Usage
```csharp
httpMock.ImportFromCurl("curl 'https://api.example.com/items?active=true' -H 'Accept: application/json'")
.RespondsWithJson(new { items = Array.Empty() });
```
## Alternative Designs
Require callers to continue translating curl commands manually into the existing fluent API. This avoids public API surface but does not address the setup cost.
## Risks
The parser should have a deliberately scoped, documented subset and provide clear errors for unsupported or malformed input. It should handle common Copy as cURL forms, including method (`-X`), URL, headers (`-H`), body (`-d`, `--data`, `--data-raw`), quoting, and line continuations. No new runtime dependency should be required.
This is an additive public API change and requires the API approval workflow. It benefits from `For(HttpMethod)` and `WithHeader` support if those land first.
## Are you willing to help with a proof-of-concept (as PR in that or a separate repo) first and as pull-request later on?
No
Contributor guide
Research direction
Start at HttpMock and inspect the existing For(HttpMethod), WithHeader, and response-builder APIs before defining the additive public API. Document the supported curl subset and API approval requirements, then validate method, URL, headers, body, quoting, line continuations, and clear errors without adding a runtime dependency.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- csharp
- Domain
- api
- Issue type
- Feature
- Difficulty
- 5/5
- Estimated time
- Over a week
- Activity status
- Active
- Clarity
- Mostly clear
- Newbie friendliness
- 45/100