cURL Examples

From DreamFactory
Jump to: navigation, search
 
(10 intermediate revisions by 2 users not shown)
Line 1: Line 1:
== cURL Examples ==
+
==Configuring Guest Access==
'''// login as an admin - POST to /system/admin/session'''
+
  
* Use returned session_token as X-DreamFactory-Session-Token header in subsequent calls
+
See [https://wiki.dreamfactory.com/DreamFactory/Tutorials/Setting_up_guest_access this page] for a number of examples pertaining to configuring guest access, roles, and CORS.
 +
 
 +
==Login as an admin - POST to /system/admin/session==
 +
 
 +
Use returned session_token as '''X-DreamFactory-Session-Token''' header in subsequent API calls.
  
 
<pre>
 
<pre>
Line 10: Line 13:
 
</pre>
 
</pre>
  
'''// login as a user - POST to /user/session'''
+
==Login as a user - POST to /user/session==
  
* Use returned session_token as X-DreamFactory-Session-Token header in subsequent calls
+
Use returned session_token as '''X-DreamFactory-Session-Token''' header in subsequent API calls.
  
 
<pre>
 
<pre>
Line 20: Line 23:
 
</pre>
 
</pre>
  
'''// get all records from table named todo'''
+
==Get all records from table named todo.==
  
 
<pre>
 
<pre>
Line 28: Line 31:
 
</pre>
 
</pre>
  
'''// create new todo'''
+
==Create a new todo record.==
  
 
<pre>
 
<pre>
Line 38: Line 41:
 
</pre>
 
</pre>
  
'''// update todo with id = 1'''
+
==Update todo record with id = 1.==
  
 
<pre>
 
<pre>
Line 48: Line 51:
 
</pre>
 
</pre>
  
'''// delete todo with id = 1'''
+
==Delete todo record with id = 1.==
  
 
<pre>
 
<pre>
Line 56: Line 59:
 
</pre>
 
</pre>
  
'''// logout as an admin - DELETE /system/admin/session'''
+
==Logout as an admin - DELETE /system/admin/session==
  
 
<pre>
 
<pre>
Line 63: Line 66:
 
</pre>
 
</pre>
  
'''// logout as a user - DELETE /user/session'''
+
==Logout as a user - DELETE /user/session==
  
 
<pre>
 
<pre>

Latest revision as of 10:45, 2 September 2020

Configuring Guest Access

See this page for a number of examples pertaining to configuring guest access, roles, and CORS.

Login as an admin - POST to /system/admin/session

Use returned session_token as X-DreamFactory-Session-Token header in subsequent API calls.

curl -i -k -3 -X POST "http://localhost:8080/api/v2/system/admin/session" \
 -d '{ "email" : "user@example.com", "password" : "pass123" }' \
 -H "Content-Type: application/json"

Login as a user - POST to /user/session

Use returned session_token as X-DreamFactory-Session-Token header in subsequent API calls.

curl -i -k -3 -X POST "http://localhost:8080/api/v2/user/session" \
 -d '{ "email" : "user@example.com", "password" : "pass123" }' \
 -H "Content-Type: application/json"

Get all records from table named todo.

curl -i -k -3 -X GET "http://localhost:8080/api/v2/db/_table/todo" \
  -H "X-DreamFactory-Api-Key: <api key for app in the apps tab>" \
  -H "X-DreamFactory-Session-Token: <session token from login response>"

Create a new todo record.

curl -i -k -3 -X POST "http://localhost:8080/api/v2/db/_table/todo" \
  -H "X-DreamFactory-Api-Key: <api key for app in the apps tab>" \
  -H "X-DreamFactory-Session-Token: <session token from login response>" \
  -H "Content-Type: application/json" \
  -d '{"resource":[{ "name" : "curl todo", "complete" : false }]}'

Update todo record with id = 1.

curl -i -k -3 -X PATCH "http://localhost:8080/api/v2/db/_table/todo/1" \
  -H "X-DreamFactory-Api-Key: <api key for app in the apps tab>" \
  -H "X-DreamFactory-Session-Token: <session token from login response>" \
  -H "Content-Type: application/json" \
  -d '{ "complete" : true }'

Delete todo record with id = 1.

curl -i -k -3 -X DELETE "http://localhost:8080/api/v2/db/_table/todo/1" \
  -H "X-DreamFactory-Api-Key: <api key for app in the apps tab>" \
  -H "X-DreamFactory-Session-Token: <session token from login response>"

Logout as an admin - DELETE /system/admin/session

curl -i -k -3 -X DELETE "http://localhost:8080/api/v2/system/admin/session" \
  -H "X-DreamFactory-Session-Token: <session token from login response>"

Logout as a user - DELETE /user/session

curl -i -k -3 -X DELETE "http://localhost:8080/api/v2/user/session" \
  -H "X-DreamFactory-Session-Token: <session token from login response>"