Skip to content

system/curl: add a small curl-like HTTP client command#3651

Merged
jerpelea merged 1 commit into
apache:masterfrom
JorgeGzm:system-curl
Jul 20, 2026
Merged

system/curl: add a small curl-like HTTP client command#3651
jerpelea merged 1 commit into
apache:masterfrom
JorgeGzm:system-curl

Conversation

@JorgeGzm

Copy link
Copy Markdown
Contributor

Summary

Add a small curl-like HTTP client command under system/curl, built on top
of the netutils/webclient library. It brings the familiar curl option
syntax to the NuttShell so HTTP servers can be exercised directly from the
target.

Supported options (a subset of the real curl, see https://curl.se/docs/manpage.html):

  • -X <method> : HTTP method (defaults to GET, or POST when a body is sent)
  • -H <header> : add a request header
  • -d <data> / -d @file : raw request body (inline or read from a file)
  • -F name=@file : multipart/form-data file upload
  • -o <file> : write the response body to a file
  • -v : verbose

HTTP only (no HTTPS).

Impact

  • New optional command guarded by CONFIG_SYSTEM_CURL (default n); no impact
    when disabled.
  • Depends on CONFIG_NETUTILS_WEBCLIENT / CONFIG_NET_TCP.
  • No change to any existing application.

Testing

  • Build Host: Linux, arm-none-eabi-gcc
  • Target: linum-stm32h753bi:curl (companion NuttX PR adds this config), STM32H753BI over Ethernet + SD card
  • nxstyle clean on system/curl/curl_main.c.

Runtime on hardware:

nsh> ifconfig
eth0    Link encap:Ethernet HWaddr 00:e0:de:ad:be:ef at RUNNING mtu 1486
        inet addr:192.168.15.3 DRaddr:192.168.15.1 Mask:255.255.255.0

GET, saving the response to a file (-o):
nsh> curl -o /mnt/dl.json http://httpbin.org/json
curl: HTTP 200
nsh> curl -o /mnt/img.png http://httpbin.org/image/png
curl: HTTP 200
nsh> ls -l /mnt/img.png
 -rw-rw-rw-        8090 /mnt/img.png

POST JSON (-d selects POST, -H sets the type); httpbin echoes it back:
nsh> curl -H Content-Type:application/json -d '{"temp":25.3,"hum":60}' http://httpbin.org/post
{
  "data": "{\"temp\":25.3,\"hum\":60}",
  "json": { "hum": 60, "temp": 25.3 },
  "url": "http://httpbin.org/post"
}
curl: HTTP 200

Custom method (-X):
nsh> curl -X PUT -d '{"x":1}' http://httpbin.org/put
curl: HTTP 200

Multipart upload (-F name=@file) and download back (-o):
nsh> curl -F file=@/mnt/nuttx_logo.png "http://192.168.15.12:8000/api/.../ota/upload?version=logo1"
{"filename":"nuttx_logo.png","sha256":"ca278dcb...","size_bytes":40343}curl: HTTP 201
nsh> curl -o /mnt/logo_back.png http://192.168.15.12:8000/api/.../ota/default/logo1/nuttx_logo.png
curl: HTTP 200
nsh> ls -l /mnt
 -rw-rw-rw-       40343 nuttx_logo.png
 -rw-rw-rw-       40343 logo_back.png

Comment thread system/curl/curl_main.c Outdated
Comment thread system/curl/curl_main.c Outdated
Comment thread system/curl/curl_main.c Outdated
Comment thread system/curl/curl_main.c Outdated
Comment thread system/curl/curl_main.c Outdated
Comment thread system/curl/curl_main.c Outdated
Comment thread system/curl/curl_main.c Outdated
Comment thread system/curl/curl_main.c Outdated
Comment thread system/curl/curl_main.c Outdated
Comment thread system/curl/curl_main.c Outdated
Add the "curl" NSH command: a command-line HTTP client built on top of
the netutils webclient library. It implements a subset of the real curl
options: GET and POST (and other methods via -X), custom request headers
(-H), a raw request body (-d, including -d @file), multipart/form-data
file uploads (-F name=@file), saving the response body to a file (-o)
and verbose output (-v). HTTP only (no HTTPS).

Signed-off-by: Jorge Guzman <jorge.gzm@gmail.com>

@cederom cederom left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thank you @JorgeGzm :-)

@jerpelea
jerpelea merged commit 865393d into apache:master Jul 20, 2026
41 checks passed
@acassis

acassis commented Jul 20, 2026

Copy link
Copy Markdown
Contributor

@xiaoxiang781216 maybe now we can remove the netutils/libcurl4nx that Sebastien started to implement and never finished

@JorgeGzm
JorgeGzm deleted the system-curl branch July 21, 2026 02:32
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

5 participants