Page MenuHomePhabricator

Add "copy as cURL" button in Api Sandbox
Open, Needs TriagePublicFeature

Assigned To
None
Authored By
Sgs
Mar 16 2023, 12:06 PM
Referenced Files
F36914300: Screenshot 2023-03-16 at 12.56.21.png
Mar 16 2023, 12:06 PM
Tokens
"Like" token, awarded by SD0001."Love" token, awarded by TheDJ."Like" token, awarded by kostajh.

Description

Feature summary (what you would like to be able to do and where):
It would be nice to have a way to serialize a request performed by the API Sandbox into some common format, for instance as a cURL command. This is similar to what browsers do in the Network tab. More formats could be also added.

Screenshot 2023-03-16 at 12.56.21.png (1×3 px, 1 MB)

Use case(s) (list the steps that you performed to discover that problem, and describe the actual underlying problem which you want to solve. Do not describe only a solution):
As a WMF developer I often want to perform requests to the MW API from other contexts than a wiki site. This can be the terminal but also an external backend service or a client application. Authenticating from a development environment can be tedious and varies across wikis. Using the API Sandbox when logged in a wiki site facilitates a lot this process but there's no easy way to reuse the request signature elsewhere.

Benefits (why should this be implemented?):
Ease the process of developing and testing mw API requests in different environments.

Event Timeline

The API sandbox output formats are customizable via the apisandbox.formatRequest JS hook (see the m3api ApiSandbox helper, source code, for an example), so you could prototype this as a user script if you want, before adding it to MediaWiki core (if that’s the intention here).

Reedy renamed this task from Add "copy as cURL" button in ApiSandBox to Add "copy as cURL" button in Api Sandbox.Jun 5 2023, 12:46 AM
Reedy updated the task description. (Show Details)

Yeah this would be nice. Also maybe fetch and mw.Api() code samples.

Note Windows and Linux wraps parameter in different ways and thus browser usually provides two options for these two formats.

One thing to note is that fetch and mw.Api() will just work if you are logged in, with curl you have to think about authentication - should we link to some documentation on how to do that? It's probably harder to figure out than the rest of the curl command.

If you copy a cURL commend from browser console it will include all cookies for the request.