Skip to content

Commit 695a155

Browse files
committed
Update curl examples to fix URL encoding
The commit improves the curl examples throughout the documentation by: 1. Moving query parameters from URL to --data-urlencode 2. Fixing escaping of $ characters in MongoDB operators 3. Removing unnecessary https:// prefix 4. Using consistent quotation style 5. Breaking long commands for better readability The changes make the examples more robust and easier to copy/paste.
1 parent 8761044 commit 695a155

File tree

9 files changed

+122
-91
lines changed

9 files changed

+122
-91
lines changed

docs/cloud/examples.adoc

Lines changed: 49 additions & 49 deletions
Original file line numberDiff line numberDiff line change
@@ -107,12 +107,12 @@ createCollections();
107107
[source,bash]
108108
----
109109
# Add categories
110-
curl -i -X POST https://[INSTANCE-URL]/categories \
110+
curl -i -X POST [INSTANCE-URL]/categories \
111111
-H "Authorization: Basic [BASIC-AUTH]" -H "Content-Type: application/json" \
112112
-d '{"name": "Electronics", "slug": "electronics", "description": "Electronic devices and accessories"}'
113113
114114
# Add products
115-
curl -i -X POST https://[INSTANCE-URL]/products \
115+
curl -i -X POST [INSTANCE-URL]/products \
116116
-H "Authorization: Basic [BASIC-AUTH]" -H "Content-Type: application/json" \
117117
-d '{
118118
"name": "Wireless Headphones",
@@ -224,16 +224,16 @@ addProduct();
224224
[source,bash]
225225
----
226226
# Search products by name
227-
curl -i "https://[INSTANCE-URL]/products?filter={'name':{\$regex:'headphones',\$options:'i'}}"
227+
curl -i "[INSTANCE-URL]/products" --data-urlencode "filter={'name':{$regex:'headphones',$options:'i'}}"
228228
229229
# Filter by price range
230-
curl "https://[INSTANCE-URL]/products?filter={'price':{\$gte:50,\$lte:150}}"
230+
curl "[INSTANCE-URL]/products" --data-urlencode "filter={'price':{$gte:50,$lte:150}}"
231231
232232
# Get products with low inventory
233-
curl "https://[INSTANCE-URL]/products?filter={'quantity':{\$lt:10}}"
233+
curl "[INSTANCE-URL]/products" --data-urlencode "filter={'quantity':{$lt:10}}"
234234
235235
# Category-based filtering with sorting
236-
curl "https://[INSTANCE-URL]/products?filter={'category':'electronics'}&sort={price:1}"
236+
curl "[INSTANCE-URL]/products" --data-urlencode "filter={'category':'electronics'}" --data-urlencode "sort={price:1}"
237237
----
238238

239239
==== HTTPie
@@ -320,12 +320,12 @@ Create a headless CMS for blogs, news sites, or documentation.
320320
[source,bash]
321321
----
322322
# Create content collections
323-
curl -i -X PUT https://[INSTANCE-URL]/articles -H "Authorization: Basic [BASIC-AUTH]"
324-
curl -i -X PUT https://[INSTANCE-URL]/authors -H "Authorization: Basic [BASIC-AUTH]"
325-
curl -i -X PUT https://[INSTANCE-URL]/media.files -H "Authorization: Basic [BASIC-AUTH]"
323+
curl -i -X PUT [INSTANCE-URL]/articles -H "Authorization: Basic [BASIC-AUTH]"
324+
curl -i -X PUT [INSTANCE-URL]/authors -H "Authorization: Basic [BASIC-AUTH]"
325+
curl -i -X PUT [INSTANCE-URL]/media.files -H "Authorization: Basic [BASIC-AUTH]"
326326
327327
# Create author
328-
curl -i -X POST https://[INSTANCE-URL]/authors \
328+
curl -i -X POST [INSTANCE-URL]/authors \
329329
-H "Authorization: Basic [BASIC-AUTH]" -H "Content-Type: application/json" \
330330
-d '{
331331
"name": "Jane Smith",
@@ -335,7 +335,7 @@ curl -i -X POST https://[INSTANCE-URL]/authors \
335335
}'
336336
337337
# Create article
338-
curl -i -X POST https://[INSTANCE-URL]/articles \
338+
curl -i -X POST [INSTANCE-URL]/articles \
339339
-H "Authorization: Basic [BASIC-AUTH]" -H "Content-Type: application/json" \
340340
-d '{
341341
"title": "Getting Started with RESTHeart Cloud",
@@ -499,13 +499,13 @@ createArticle();
499499
[source,bash]
500500
----
501501
# Get published articles
502-
curl "https://[INSTANCE-URL]/articles?filter={'status':'published'}&sort={publishedAt:-1}"
502+
curl "[INSTANCE-URL]/articles" --data-urlencode "filter={'status':'published'}" --data-urlencode "sort={publishedAt:-1}"
503503
504504
# Get article by slug
505-
curl "https://[INSTANCE-URL]/articles?filter={'slug':'getting-started-restheart-cloud'}"
505+
curl "[INSTANCE-URL]/articles" --data-urlencode "filter={'slug':'getting-started-restheart-cloud'}"
506506
507507
# Search articles
508-
curl "https://[INSTANCE-URL]/articles?filter={\$text:{\$search:'RESTHeart API'}}"
508+
curl "[INSTANCE-URL]/articles" --data-urlencode "filter={$text:{$search:'RESTHeart API'}}"
509509
----
510510

511511
==== HTTPie
@@ -579,12 +579,12 @@ Build a complete social platform with users, posts, likes, and real-time feature
579579
[source,bash]
580580
----
581581
# Create social app collections
582-
curl -i -X PUT https://[INSTANCE-URL]/profiles -H "Authorization: Basic [BASIC-AUTH]"
583-
curl -i -X PUT https://[INSTANCE-URL]/posts -H "Authorization: Basic [BASIC-AUTH]"
584-
curl -i -X PUT https://[INSTANCE-URL]/followers -H "Authorization: Basic [BASIC-AUTH]"
582+
curl -i -X PUT [INSTANCE-URL]/profiles -H "Authorization: Basic [BASIC-AUTH]"
583+
curl -i -X PUT [INSTANCE-URL]/posts -H "Authorization: Basic [BASIC-AUTH]"
584+
curl -i -X PUT [INSTANCE-URL]/followers -H "Authorization: Basic [BASIC-AUTH]"
585585
586586
# Create user profile
587-
curl -i -X POST https://[INSTANCE-URL]/profiles \
587+
curl -i -X POST [INSTANCE-URL]/profiles \
588588
-H "Authorization: Basic [BASIC-AUTH]" -H "Content-Type: application/json" \
589589
-d '{
590590
"username": "johndoe",
@@ -602,7 +602,7 @@ curl -i -X POST https://[INSTANCE-URL]/profiles \
602602
}'
603603
604604
# Create a post
605-
curl -i -X POST https://[INSTANCE-URL]/posts \
605+
curl -i -X POST [INSTANCE-URL]/posts \
606606
-H "Authorization: Basic [BASIC-AUTH]" -H "Content-Type: application/json" \
607607
-d '{
608608
"author": "johndoe",
@@ -773,13 +773,13 @@ createPost();
773773
[source,bash]
774774
----
775775
# Get user timeline (posts from followed users)
776-
curl "https://[INSTANCE-URL]/posts?filter={'author':{\$in:['user1','user2','user3']}}&sort={createdAt:-1}"
776+
curl "[INSTANCE-URL]/posts" --data-urlencode "filter={'author':{$in:['user1','user2','user3']}}" --data-urlencode "sort={createdAt:-1}"
777777
778778
# Search posts by hashtag
779-
curl "https://[INSTANCE-URL]/posts?filter={'hashtags':{\$in:['#api']}}"
779+
curl "[INSTANCE-URL]/posts" --data-urlencode "filter={'hashtags':{$in:['#api']}}"
780780
781781
# Get user's posts
782-
curl "https://[INSTANCE-URL]/posts?filter={'author':'johndoe'}&sort={createdAt:-1}"
782+
curl "[INSTANCE-URL]/posts" --data-urlencode "filter={'author':'johndoe'}" --data-urlencode "sort={createdAt:-1}"
783783
----
784784

785785
==== HTTPie
@@ -850,12 +850,12 @@ Create a comprehensive fitness backend with workouts, progress tracking, and goa
850850
[source,bash]
851851
----
852852
# Setup fitness collections
853-
curl -i -X PUT https://[INSTANCE-URL]/workouts -H "Authorization: Basic [BASIC-AUTH]"
854-
curl -i -X PUT https://[INSTANCE-URL]/exercises -H "Authorization: Basic [BASIC-AUTH]"
855-
curl -i -X PUT https://[INSTANCE-URL]/progress -H "Authorization: Basic [BASIC-AUTH]"
853+
curl -i -X PUT [INSTANCE-URL]/workouts -H "Authorization: Basic [BASIC-AUTH]"
854+
curl -i -X PUT [INSTANCE-URL]/exercises -H "Authorization: Basic [BASIC-AUTH]"
855+
curl -i -X PUT [INSTANCE-URL]/progress -H "Authorization: Basic [BASIC-AUTH]"
856856
857857
# Add exercise definitions
858-
curl -i -X POST https://[INSTANCE-URL]/exercises \
858+
curl -i -X POST [INSTANCE-URL]/exercises \
859859
-H "Authorization: Basic [BASIC-AUTH]" -H "Content-Type: application/json" \
860860
-d '{
861861
"name": "Push-ups",
@@ -867,7 +867,7 @@ curl -i -X POST https://[INSTANCE-URL]/exercises \
867867
}'
868868
869869
# Log workout
870-
curl -i -X POST https://[INSTANCE-URL]/workouts \
870+
curl -i -X POST [INSTANCE-URL]/workouts \
871871
-H "Authorization: Basic [BASIC-AUTH]" -H "Content-Type: application/json" \
872872
-d '{
873873
"userId": "user123",
@@ -1046,12 +1046,12 @@ Collect and analyze data from home sensors and devices.
10461046
[source,bash]
10471047
----
10481048
# Create IoT collections
1049-
curl -i -X PUT https://[INSTANCE-URL]/devices -H "Authorization: Basic [BASIC-AUTH]"
1050-
curl -i -X PUT https://[INSTANCE-URL]/readings -H "Authorization: Basic [BASIC-AUTH]"
1051-
curl -i -X PUT https://[INSTANCE-URL]/alerts -H "Authorization: Basic [BASIC-AUTH]"
1049+
curl -i -X PUT [INSTANCE-URL]/devices -H "Authorization: Basic [BASIC-AUTH]"
1050+
curl -i -X PUT [INSTANCE-URL]/readings -H "Authorization: Basic [BASIC-AUTH]"
1051+
curl -i -X PUT [INSTANCE-URL]/alerts -H "Authorization: Basic [BASIC-AUTH]"
10521052
10531053
# Register device
1054-
curl -i -X POST https://[INSTANCE-URL]/devices \
1054+
curl -i -X POST [INSTANCE-URL]/devices \
10551055
-H "Authorization: Basic [BASIC-AUTH]" -H "Content-Type: application/json" \
10561056
-d '{
10571057
"deviceId": "temp-sensor-01",
@@ -1064,7 +1064,7 @@ curl -i -X POST https://[INSTANCE-URL]/devices \
10641064
}'
10651065
10661066
# Submit sensor reading
1067-
curl -i -X POST https://[INSTANCE-URL]/readings \
1067+
curl -i -X POST [INSTANCE-URL]/readings \
10681068
-H "Authorization: Basic [BASIC-AUTH]" -H "Content-Type: application/json" \
10691069
-d '{
10701070
"deviceId": "temp-sensor-01",
@@ -1215,10 +1215,10 @@ submitReading();
12151215
[source,bash]
12161216
----
12171217
# Get recent readings
1218-
curl -i "https://[INSTANCE-URL]/readings?filter={'timestamp':{\$gte:'2024-01-15T00:00:00Z'}}&sort={timestamp:-1}"
1218+
curl -i "[INSTANCE-URL]/readings" --data-urlencode "filter={'timestamp':{$gte:'2024-01-15T00:00:00Z'}}" --data-urlencode "sort={timestamp:-1}"
12191219
12201220
# Average temperature by location
1221-
curl -X POST https://[INSTANCE-URL]/readings/_aggrs/avg-temp-by-location \
1221+
curl -X POST [INSTANCE-URL]/readings/_aggrs/avg-temp-by-location \
12221222
-H "Authorization: Basic [BASIC-AUTH]" -H "Content-Type: application/json" \
12231223
-d '[
12241224
{"$match": {"timestamp": {"$gte": "2024-01-15T00:00:00Z"}}},
@@ -1301,11 +1301,11 @@ Track air quality, weather conditions, and environmental data.
13011301
[source,bash]
13021302
----
13031303
# Environmental monitoring setup
1304-
curl -X PUT https://[INSTANCE-URL]/stations -H "Authorization: Basic [BASIC-AUTH]"
1305-
curl -X PUT https://[INSTANCE-URL]/measurements -H "Authorization: Basic [BASIC-AUTH]"
1304+
curl -X PUT [INSTANCE-URL]/stations -H "Authorization: Basic [BASIC-AUTH]"
1305+
curl -X PUT [INSTANCE-URL]/measurements -H "Authorization: Basic [BASIC-AUTH]"
13061306
13071307
# Register monitoring station
1308-
curl -X POST https://[INSTANCE-URL]/stations \
1308+
curl -X POST [INSTANCE-URL]/stations \
13091309
-H "Authorization: Basic [BASIC-AUTH]" -H "Content-Type: application/json" \
13101310
-d '{
13111311
"stationId": "ENV-NYC-001",
@@ -1320,7 +1320,7 @@ curl -X POST https://[INSTANCE-URL]/stations \
13201320
}'
13211321
13221322
# Submit environmental measurement
1323-
curl -X POST https://[INSTANCE-URL]/measurements \
1323+
curl -X POST [INSTANCE-URL]/measurements \
13241324
-H "Authorization: Basic [BASIC-AUTH]" -H "Content-Type: application/json" \
13251325
-d '{
13261326
"stationId": "ENV-NYC-001",
@@ -1491,12 +1491,12 @@ Create a comprehensive analytics backend for business metrics.
14911491
[source,bash]
14921492
----
14931493
# Business analytics setup
1494-
curl -X PUT https://[INSTANCE-URL]/sales -H "Authorization: Basic [BASIC-AUTH]"
1495-
curl -X PUT https://[INSTANCE-URL]/customers -H "Authorization: Basic [BASIC-AUTH]"
1496-
curl -X PUT https://[INSTANCE-URL]/analytics-products -H "Authorization: Basic [BASIC-AUTH]"
1494+
curl -X PUT [INSTANCE-URL]/sales -H "Authorization: Basic [BASIC-AUTH]"
1495+
curl -X PUT [INSTANCE-URL]/customers -H "Authorization: Basic [BASIC-AUTH]"
1496+
curl -X PUT [INSTANCE-URL]/analytics-products -H "Authorization: Basic [BASIC-AUTH]"
14971497
14981498
# Record sale
1499-
curl -X POST https://[INSTANCE-URL]/sales \
1499+
curl -X POST [INSTANCE-URL]/sales \
15001500
-H "Authorization: Basic [BASIC-AUTH]" -H "Content-Type: application/json" \
15011501
-d '{
15021502
"orderId": "ORD-2024-001",
@@ -1633,7 +1633,7 @@ recordSale();
16331633
[source,bash]
16341634
----
16351635
# Daily sales aggregation
1636-
curl -X POST https://[INSTANCE-URL]/sales/_aggrs/daily-sales \
1636+
curl -X POST [INSTANCE-URL]/sales/_aggrs/daily-sales \
16371637
-H "Authorization: Basic [BASIC-AUTH]" -H "Content-Type: application/json" \
16381638
-d '[
16391639
{"$match": {"date": {"$gte": "2024-01-01T00:00:00Z"}}},
@@ -1647,7 +1647,7 @@ curl -X POST https://[INSTANCE-URL]/sales/_aggrs/daily-sales \
16471647
]'
16481648
16491649
# Top products by revenue
1650-
curl -X POST https://[INSTANCE-URL]/sales/_aggrs/top-products \
1650+
curl -X POST [INSTANCE-URL]/sales/_aggrs/top-products \
16511651
-H "Authorization: Basic [BASIC-AUTH]" -H "Content-Type: application/json" \
16521652
-d '[
16531653
{"$unwind": "$items"},
@@ -1936,13 +1936,13 @@ curl -X POST https://[instance].restheart.com/public-datasets \
19361936
curl "https://[instance].restheart.com/announcements"
19371937
19381938
# Get active announcements
1939-
curl "https://[instance].restheart.com/announcements?filter={'expiresAt':{\$gte:'2024-01-15T00:00:00Z'}}"
1939+
curl "https://[instance].restheart.com/announcements" --data-urlencode "filter={'expiresAt':{$gte:'2024-01-15T00:00:00Z'}}"
19401940
19411941
# Browse public datasets
19421942
curl "https://[instance].restheart.com/public-datasets"
19431943
19441944
# Search datasets by category
1945-
curl "https://[instance].restheart.com/public-datasets?filter={'category':'environmental'}"
1945+
curl "https://[instance].restheart.com/public-datasets" --data-urlencode "filter={'category':'environmental'}"
19461946
19471947
# Get specific dataset information
19481948
curl "https://[instance].restheart.com/public-datasets/city-weather-stations"
@@ -2079,13 +2079,13 @@ curl -X POST https://[instance].restheart.com/events \
20792079
# Public users can access these without authentication
20802080
20812081
# Get upcoming events
2082-
curl "https://[instance].restheart.com/events?sort={startDate:1}"
2082+
curl "https://[instance].restheart.com/events" --data-urlencode "sort={startDate:1}"
20832083
20842084
# Filter events by category
2085-
curl "https://[instance].restheart.com/events?filter={'category':'workshop'}"
2085+
curl "https://[instance].restheart.com/events" --data-urlencode "filter={'category':'workshop'}"
20862086
20872087
# Get events for a specific date range
2088-
curl "https://[instance].restheart.com/events?filter={'startDate':{\$gte:'2024-01-20T00:00:00Z',\$lt:'2024-01-27T00:00:00Z'}}"
2088+
curl "https://[instance].restheart.com/events" --data-urlencode "filter={'startDate':{$gte:'2024-01-20T00:00:00Z',$lt:'2024-01-27T00:00:00Z'}}"
20892089
----
20902090

20912091
===== Security Considerations for Public Access

docs/mongodb-rest/aggregations.adoc

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -165,8 +165,9 @@ When executing the aggregation, provide variable values using the `avars` query
165165
==== cURL
166166
[source,bash]
167167
----
168-
curl -i -X GET "[INSTANCE-URL]/mycollection/_aggrs/sales-by-product?avars={\"productName\":\"Widget Pro\"}" \
169-
-u "[BASIC-AUTH]"
168+
curl -i -X GET "[INSTANCE-URL]/mycollection/_aggrs/sales-by-product" \
169+
-u "[BASIC-AUTH]" \
170+
--data-urlencode 'avars={"productName":"Widget Pro"}'
170171
----
171172

172173
==== HTTPie
@@ -234,8 +235,9 @@ You can access nested properties in variables using dot notation:
234235
==== cURL
235236
[source,bash]
236237
----
237-
curl -i -X GET "[INSTANCE-URL]/mycollection/_aggrs/my-pipeline?avars={\"config\":{\"limit\":10,\"skip\":20}}" \
238-
-u "[BASIC-AUTH]"
238+
curl -i -X GET "[INSTANCE-URL]/mycollection/_aggrs/my-pipeline" \
239+
-u "[BASIC-AUTH]" \
240+
--data-urlencode 'avars={"config":{"limit":10,"skip":20}}'
239241
----
240242

241243
==== HTTPie

docs/mongodb-rest/files.adoc

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -314,8 +314,9 @@ You can query files by their metadata just like regular documents:
314314

315315
[source,bash]
316316
----
317-
curl -i -X GET "[INSTANCE-URL]/mybucket.files?filter={\"metadata.author\":\"SoftInstigate\"}" \
318-
-H "Authorization: Basic [BASIC-AUTH]"
317+
curl -i -X GET "[INSTANCE-URL]/mybucket.files" \
318+
-H "Authorization: Basic [BASIC-AUTH]" \
319+
--data-urlencode 'filter={"metadata.author":"SoftInstigate"}'
319320
----
320321

321322
==== HTTPie

docs/mongodb-rest/json-schema-validation.adoc

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -623,7 +623,8 @@ The jsonSchema validator has some limitations to be aware of:
623623
==== cURL
624624
[source,bash]
625625
----
626-
curl -i -X PATCH "[INSTANCE-URL]/addresses/*?filter={\"country\":\"Italy\"}" \
626+
curl -i -X PATCH "[INSTANCE-URL]/addresses/*" \
627+
--data-urlencode 'filter={"country":"Italy"}' \
627628
-H "Authorization: Basic [BASIC-AUTH]" \
628629
-H "Content-Type: application/json" \
629630
-d '{ "updated": true }'

0 commit comments

Comments
 (0)