Skip to content
Snippets Groups Projects

Updated README.md with instructions for performing requests

1 file
+ 47
0
Compare changes
  • Side-by-side
  • Inline
+ 47
0
@@ -54,6 +54,53 @@ try {
7. Navigate to Administration > Configuration > REST API Access Token
and set API login options: via username or via user mail.
API requests
------------
Provided that you configured the module to login using email, you can
performing the API request to authenticate on the Drupal site running
on https://localhost:3000:
```bash
curl -X POST \
-H "Content-type: application/json" \
-i -d '{"login":"user@example.com", "password":"123456789"}' \
https://localhost:3000/api/v1/auth/token?_format=json
```
This will return the token and secret, see output:
```
HTTP/2 200
cache-control: must-revalidate, no-cache, private
content-language: en
content-type: application/json
date: Fri, 25 Apr 2025 11:10:38 GMT
expires: Sun, 19 Nov 1978 05:00:00 GMT
server: nginx
vary: Origin
x-content-type-options: nosniff
x-frame-options: SAMEORIGIN
x-generator: Drupal 11 (https://www.drupal.org)
content-length: 163
{"token":"e5be77f71f7e828f81e00472bd1bb7eb1f708c321b94693e6115f34cb8596ee1","secret":"ec27e8400927d2311260ee3e8c2907be61da8f59e55dce9ef9c813489bf7c32a","userId":2}
```
Now you can use the token to do subsequent requests to any REST API in Drupal, example:
```bash
curl -X GET \
-H "Accept: application/json" \
-i \
-H "X-AUTH-TOKEN: e5be77f71f7e828f81e00472bd1bb7eb1f708c321b94693e6115f34cb8596ee1" \
https://localhost:3000/user/1?_format=json
```
Will return:
```
{"uid":[{"value":2}],"uuid":[{"value":"341f1062-b308-400f-ac3d-27c3d523d151"}],"langcode":[{"value":"en"}],"preferred_langcode":[{"value":"en"}],"preferred_admin_langcode":[{"value":"en"}],"name":[{"value":"tester"}],"mail":[{"value":"user@example.com"}],"timezone":[{"value":"Europe\/London"}],"created":[{"value":"2025-04-25T08:16:38+00:00","format":"Y-m-d\\TH:i:sP"}],"changed":[{"value":"2025-04-25T08:16:38+00:00","format":"Y-m-d\\TH:i:sP"}],"default_langcode":[{"value":true}],"user_picture":[]}
```
MAINTAINERS
-----------
Loading