Skip to content

Commit d590bc3

Browse files
committed
doc: Add HTTP client migration notes for NCS Serial LTE Modem
Document the changes required to migrate from the NCS SLM HTTP client API to the new HTTP client API in the Serial Modem add-on. Rename the <socket_fd> parameter to <handle> for consistency with the AT socket documentation. Jira: SM-298 Signed-off-by: Juha Ylinen <juha.ylinen@nordicsemi.no>
1 parent c9ac337 commit d590bc3

3 files changed

Lines changed: 126 additions & 34 deletions

File tree

app/src/sm_at_httpc.c

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -584,7 +584,7 @@ static bool http_headers_complete(struct http_request *req, char *header_end,
584584
/*
585585
* Keep piggybacked body bytes (if any) for the first pull.
586586
* Stop XAPOLL so only the host drives reception via
587-
* AT#XHTTPCDATA=<socket_fd>.
587+
* AT#XHTTPCDATA=<handle>.
588588
*/
589589
if (body_len > 0)
590590
memmove(req->recv_buf, req->recv_buf + body_offset, body_len);
@@ -992,7 +992,7 @@ STATIC int handle_at_httpcreq(enum at_parser_cmd_type cmd_type, struct at_parser
992992
/* Validate socket exists */
993993
sock = find_socket(socket_fd);
994994
if (!sock) {
995-
LOG_ERR("Invalid socket FD: %d", socket_fd);
995+
LOG_ERR("Invalid socket fd: %d", socket_fd);
996996
return -EINVAL;
997997
}
998998

@@ -1191,7 +1191,7 @@ STATIC int handle_at_httpcreq(enum at_parser_cmd_type cmd_type, struct at_parser
11911191
}
11921192

11931193
case AT_PARSER_CMD_TYPE_TEST:
1194-
rsp_send("\r\n#XHTTPCREQ: <socket_fd>,<url>,<method>"
1194+
rsp_send("\r\n#XHTTPCREQ: <handle>,<url>,<method>"
11951195
"[,<auto_reception>[,<body_len>[,<header>]...]]\r\n");
11961196

11971197
err = 0;
@@ -1325,7 +1325,7 @@ STATIC int handle_at_httpcdata(enum at_parser_cmd_type cmd_type, struct at_parse
13251325
}
13261326

13271327
case AT_PARSER_CMD_TYPE_TEST:
1328-
rsp_send("\r\n#XHTTPCDATA: <socket_fd>[,<length>]\r\n");
1328+
rsp_send("\r\n#XHTTPCDATA: <handle>[,<length>]\r\n");
13291329

13301330
err = 0;
13311331
break;
@@ -1371,7 +1371,7 @@ STATIC int handle_at_httpccancel(enum at_parser_cmd_type cmd_type, struct at_par
13711371
break;
13721372

13731373
case AT_PARSER_CMD_TYPE_TEST:
1374-
rsp_send("\r\n#XHTTPCCANCEL: <socket_fd>\r\n");
1374+
rsp_send("\r\n#XHTTPCCANCEL: <handle>\r\n");
13751375
break;
13761376

13771377
default:

doc/app/at_httpc.rst

Lines changed: 28 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -35,10 +35,10 @@ Syntax
3535

3636
::
3737

38-
AT#XHTTPCREQ=<socket_fd>,<url>,<method>[,<auto_reception>[,<body_len>[,<header 1>[,<header 2>[...]]]]]
38+
AT#XHTTPCREQ=<handle>,<url>,<method>[,<auto_reception>[,<body_len>[,<header 1>[,<header 2>[...]]]]]
3939

40-
* The ``<socket_fd>`` parameter is an integer.
41-
It identifies the connected socket file descriptor returned by ``AT#XSOCKET`` or ``AT#XSSOCKET``.
40+
* The ``<handle>`` parameter is an integer.
41+
It identifies the connected socket handle returned by ``AT#XSOCKET`` or ``AT#XSSOCKET``, and connected by ``AT#XCONNECT``.
4242

4343
* The ``<url>`` parameter is a string.
4444
It specifies the full URL of the request, for example, ``http://host/path`` or ``https://host/path``.
@@ -91,20 +91,20 @@ Response syntax
9191

9292
::
9393

94-
#XHTTPCREQ: <socket_fd>
94+
#XHTTPCREQ: <handle>
9595
OK
9696

97-
* The ``<socket_fd>`` parameter is an integer.
97+
* The ``<handle>`` parameter is an integer.
9898
It identifies the socket.
9999

100100
Unsolicited notification
101101
~~~~~~~~~~~~~~~~~~~~~~~~
102102

103103
``#XHTTPCHEAD`` is emitted when response headers have been parsed::
104104

105-
#XHTTPCHEAD: <socket_fd>,<status_code>,<content_length>
105+
#XHTTPCHEAD: <handle>,<status_code>,<content_length>
106106

107-
* The ``<socket_fd>`` parameter is an integer.
107+
* The ``<handle>`` parameter is an integer.
108108
It identifies the socket.
109109
* The ``<status_code>`` parameter is an integer.
110110
It contains the HTTP status code returned by the server.
@@ -113,11 +113,11 @@ Unsolicited notification
113113

114114
``#XHTTPCDATA`` is emitted in automatic mode for each received body chunk::
115115

116-
#XHTTPCDATA: <socket_fd>,<offset>,<length>
116+
#XHTTPCDATA: <handle>,<offset>,<length>
117117

118118
The notification line is terminated with ``\r\n`` and the raw body bytes follow immediately with no additional separator.
119119

120-
* The ``<socket_fd>`` parameter is an integer.
120+
* The ``<handle>`` parameter is an integer.
121121
It identifies the socket.
122122
* The ``<offset>`` parameter is an integer.
123123
It contains the number of body bytes already delivered before this chunk.
@@ -126,9 +126,9 @@ The notification line is terminated with ``\r\n`` and the raw body bytes follow
126126

127127
``#XHTTPCSTAT`` is emitted when the request completes, fails, or is cancelled::
128128

129-
#XHTTPCSTAT: <socket_fd>,<status_code>,<total_bytes>
129+
#XHTTPCSTAT: <handle>,<status_code>,<total_bytes>
130130

131-
* The ``<socket_fd>`` parameter is an integer.
131+
* The ``<handle>`` parameter is an integer.
132132
It identifies the socket.
133133
* The ``<status_code>`` parameter is an integer.
134134
It contains the HTTP status code on success, or ``-1`` on failure, cancel, or timeout.
@@ -252,15 +252,15 @@ Response syntax
252252

253253
::
254254

255-
#XHTTPCREQ: <socket_fd>,<url>,<method>[,<auto_reception>[,<body_len>[,<header>]...]]
255+
#XHTTPCREQ: <handle>,<url>,<method>[,<auto_reception>[,<body_len>[,<header>]...]]
256256

257257
Example
258258
~~~~~~~
259259

260260
::
261261

262262
AT#XHTTPCREQ=?
263-
#XHTTPCREQ: <socket_fd>,<url>,<method>[,<auto_reception>[,<body_len>[,<header>]...]]
263+
#XHTTPCREQ: <handle>,<url>,<method>[,<auto_reception>[,<body_len>[,<header>]...]]
264264
OK
265265

266266
HTTP data pull #XHTTPCDATA
@@ -278,9 +278,9 @@ Syntax
278278

279279
::
280280

281-
AT#XHTTPCDATA=<socket_fd>[,<length>]
281+
AT#XHTTPCDATA=<handle>[,<length>]
282282

283-
* The ``<socket_fd>`` parameter is an integer.
283+
* The ``<handle>`` parameter is an integer.
284284
It identifies the socket used when starting the manual-mode request.
285285

286286
* The ``<length>`` parameter is an optional integer.
@@ -292,7 +292,7 @@ Response syntax
292292

293293
When body data is available::
294294

295-
#XHTTPCDATA: <socket_fd>,<offset>,<length>
295+
#XHTTPCDATA: <handle>,<offset>,<length>
296296
<length bytes of raw body data>
297297
OK
298298

@@ -302,10 +302,10 @@ The ``#XHTTPCDATA:`` line is terminated with ``\r\n``.
302302

303303
When the socket buffer is temporarily empty (EAGAIN)::
304304

305-
#XHTTPCDATA: <socket_fd>,<offset>,0
305+
#XHTTPCDATA: <handle>,<offset>,0
306306
OK
307307

308-
* The ``<socket_fd>`` parameter is an integer.
308+
* The ``<handle>`` parameter is an integer.
309309
It identifies the socket.
310310
* The ``<offset>`` parameter is an integer.
311311
It contains the number of body bytes already delivered before this pull.
@@ -319,8 +319,8 @@ when the ``Content-Length`` bytes have all been forwarded.
319319

320320
.. note::
321321

322-
Retry the pull after a brief delay when ``#XHTTPCDATA: <socket_fd>,<offset>,0`` is received.
323-
Use ``AT#XHTTPCCANCEL=<socket_fd>`` to cancel if no more data is needed.
322+
Retry the pull after a brief delay when ``#XHTTPCDATA: <handle>,<offset>,0`` is received.
323+
Use ``AT#XHTTPCCANCEL=<handle>`` to cancel if no more data is needed.
324324

325325
Example
326326
~~~~~~~
@@ -356,15 +356,15 @@ Response syntax
356356

357357
::
358358

359-
#XHTTPCDATA: <socket_fd>[,<length>]
359+
#XHTTPCDATA: <handle>[,<length>]
360360

361361
Example
362362
~~~~~~~
363363

364364
::
365365

366366
AT#XHTTPCDATA=?
367-
#XHTTPCDATA: <socket_fd>[,<length>]
367+
#XHTTPCDATA: <handle>[,<length>]
368368
OK
369369

370370
Idle timeout
@@ -377,7 +377,7 @@ The timer resets each time data is sent or received:
377377
* Receiving response headers or body bytes.
378378
* Pulling a body chunk in manual mode (``AT#XHTTPCDATA``).
379379

380-
If no such activity occurs within the configured window, the request is aborted and ``#XHTTPCSTAT: <socket_fd>,-1,<total_bytes>`` is emitted.
380+
If no such activity occurs within the configured window, the request is aborted and ``#XHTTPCSTAT: <handle>,-1,<total_bytes>`` is emitted.
381381
The timeout is enforced by a background timer that fires independently of normal socket poll events, so a server that stalls silently (no TCP RST or FIN) is also detected.
382382

383383
HTTP request cancel #XHTTPCCANCEL
@@ -395,12 +395,12 @@ Syntax
395395

396396
::
397397

398-
AT#XHTTPCCANCEL=<socket_fd>
398+
AT#XHTTPCCANCEL=<handle>
399399

400-
* The ``<socket_fd>`` parameter is an integer.
400+
* The ``<handle>`` parameter is an integer.
401401
It identifies the socket of the request to cancel.
402402

403-
An unsolicited ``#XHTTPCSTAT: <socket_fd>,-1,<total_bytes>`` notification is emitted after cancellation, where ``<total_bytes>`` is the number of response body bytes already delivered to the host.
403+
An unsolicited ``#XHTTPCSTAT: <handle>,-1,<total_bytes>`` notification is emitted after cancellation, where ``<total_bytes>`` is the number of response body bytes already delivered to the host.
404404

405405
Example
406406
~~~~~~~
@@ -428,13 +428,13 @@ Response syntax
428428

429429
::
430430

431-
#XHTTPCCANCEL: <socket_fd>
431+
#XHTTPCCANCEL: <handle>
432432

433433
Example
434434
~~~~~~~
435435

436436
::
437437

438438
AT#XHTTPCCANCEL=?
439-
#XHTTPCCANCEL: <socket_fd>
439+
#XHTTPCCANCEL: <handle>
440440
OK

doc/releases/migration_notes_ncs_slm_v3.1.x.rst

Lines changed: 93 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -231,6 +231,99 @@ Migration example:
231231
AT#XRECV=2,0,0,10 // Receive data from socket handle 2 with mode 0, no flags, 10s timeout
232232
AT#XCLOSE=1 // Close socket handle 1
233233
234+
HTTP client changes
235+
-------------------
236+
237+
The HTTP client has been redesigned from a dedicated connection-oriented interface to a socket-based interface.
238+
The old |NCS| SLM HTTP client kept its own HTTP connection state with ``AT#XHTTPCCON``, sent requests with ``AT#XHTTPCREQ``, and delivered the raw HTTP response stream followed by ``#XHTTPCRSP`` notifications.
239+
In |SM|, the HTTP client reuses Socket AT commands for transport setup and provides dedicated HTTP AT commands for requests and notifications, including headers, body data, and completion status.
240+
241+
The following is the list of changes:
242+
243+
* Removed ``AT#XHTTPCCON``.
244+
245+
* Create a plain TCP socket with ``AT#XSOCKET`` or a TLS socket with ``AT#XSSOCKET``.
246+
* Configure TLS options such as security tag and peer verification with ``AT#XSSOCKETOPT``.
247+
* Establish the transport connection with ``AT#XCONNECT=<handle>,<host>,<port>``.
248+
* Close the connection with ``AT#XCLOSE`` when no more requests are needed.
249+
250+
* Updated ``AT#XHTTPCREQ`` to operate on an already connected socket.
251+
252+
* Old syntax: ``AT#XHTTPCREQ=<method>,<resource>[,<headers>[,<content_type>,<content_length>[,<chunked_transfer>]]]``
253+
* New syntax: ``AT#XHTTPCREQ=<handle>,<url>,<method>[,<auto_reception>[,<body_len>[,<header 1>[,<header 2>[...]]]]]``
254+
255+
* Changed request parameter model.
256+
257+
* ``<method>`` changed from a string such as ``"GET"`` or ``"POST"`` to an integer:
258+
259+
* ``0`` - GET
260+
* ``1`` - POST
261+
* ``2`` - PUT
262+
* ``3`` - DELETE
263+
* ``4`` - HEAD
264+
265+
* ``<resource>`` is replaced by a full ``<url>`` parameter.
266+
* Optional headers are no longer passed as one CRLF-delimited string.
267+
Each header is now passed as a separate optional parameter.
268+
* For POST and PUT, the body upload length is given with ``<body_len>``.
269+
The command then enters data mode and the host must send exactly that many bytes.
270+
* For GET or HEAD requests with extra headers, set ``<body_len>`` to ``0`` as a placeholder before the header parameters.
271+
272+
* Changed response delivery model.
273+
274+
* Removed the old raw response plus ``#XHTTPCRSP: <received_byte_count>,<state>`` framing.
275+
* Response headers are now reported with ``#XHTTPCHEAD: <handle>,<status_code>,<content_length>``.
276+
* In automatic mode, response body chunks are reported with ``#XHTTPCDATA: <handle>,<offset>,<length>`` and the raw body bytes follow immediately.
277+
* In manual mode, the host pulls body chunks explicitly with ``AT#XHTTPCDATA=<handle>[,<length>]``.
278+
* Request completion including failure, timeout, or cancel is reported with ``#XHTTPCSTAT: <handle>,<status_code>,<total_bytes>``.
279+
280+
* Added request cancellation with ``AT#XHTTPCCANCEL=<handle>``.
281+
282+
Migration example:
283+
284+
Old approach (|NCS| SLM):
285+
286+
.. code-block::
287+
288+
AT#XHTTPCCON=1,"postman-echo.com",80
289+
#XHTTPCCON: 1
290+
OK
291+
292+
AT#XHTTPCREQ="GET","/get?foo1=bar1&foo2=bar2"
293+
OK
294+
#XHTTPCREQ: 0
295+
296+
HTTP/1.1 200 OK
297+
<headers>
298+
299+
#XHTTPCRSP: 244,1
300+
<244 bytes of body>
301+
302+
New approach (|SM|):
303+
304+
.. code-block::
305+
306+
AT#XSOCKET=1,1,0
307+
#XSOCKET: 0,1,6
308+
OK
309+
310+
AT#XCONNECT=0,"postman-echo.com",80
311+
#XCONNECT: 0,1
312+
OK
313+
314+
AT#XHTTPCREQ=0,"http://postman-echo.com/get?foo1=bar1&foo2=bar2",0
315+
#XHTTPCREQ: 0
316+
OK
317+
318+
#XHTTPCHEAD: 0,200,244
319+
320+
#XHTTPCDATA: 0,0,244
321+
<244 bytes of body>
322+
323+
#XHTTPCSTAT: 0,200,244
324+
325+
For full details of the new interface, see :ref:`SM_AT_HTTPC` and :ref:`SM_AT_SOCKET`.
326+
234327
PPP connection management changes
235328
---------------------------------
236329

@@ -589,7 +682,6 @@ If you need any of those features with this |SM|, please contact customer suppor
589682
590683
OK
591684
592-
* HTTP client functionality, including ``AT#XHTTPCCON`` and ``AT#XHTTPCREQ`` commands, and ``#XHTTPCRSP`` notification.
593685
* FTP and TFTP clients, including ``AT#XFTP`` and ``AT#XTFTP`` commands.
594686
* The ``AT#XGPIO`` AT command.
595687
* The ``AT#XPOLL`` command.

0 commit comments

Comments
 (0)