feat: implement basic API
with authorization and validation
This commit is contained in:
parent
b033262bd7
commit
6fbeedd50c
21 changed files with 599 additions and 10 deletions
15
cmd/curl_get_entries.sh
Executable file
15
cmd/curl_get_entries.sh
Executable file
|
|
@ -0,0 +1,15 @@
|
|||
#!/usr/bin/env bash
|
||||
|
||||
# TOKEN="your_api_token_here"
|
||||
# ensure to have set TOKEN to a valid value before running
|
||||
# ideally add this to an .envrc file and source it
|
||||
# tokens need to be created with tinker or similar method
|
||||
|
||||
|
||||
URL='http://127.0.0.1:8000/api/entries'
|
||||
|
||||
curl -s -X GET \
|
||||
-H "Authorization: Bearer $TOKEN" \
|
||||
-H "Accept: application/json" \
|
||||
$URL
|
||||
|
||||
13
cmd/curl_get_entries_anon.sh
Executable file
13
cmd/curl_get_entries_anon.sh
Executable file
|
|
@ -0,0 +1,13 @@
|
|||
#!/usr/bin/env bash
|
||||
|
||||
# this should fail, no token provided
|
||||
# users need to be authenticated and have been
|
||||
# granted access to view entries by being given
|
||||
# a token
|
||||
|
||||
URL='http://127.0.0.1:8000/api/entries'
|
||||
|
||||
curl -s -X GET \
|
||||
-H "Accept: application/json" \
|
||||
$URL
|
||||
|
||||
20
cmd/curl_post_entry.sh
Executable file
20
cmd/curl_post_entry.sh
Executable file
|
|
@ -0,0 +1,20 @@
|
|||
#!/usr/bin/env bash
|
||||
|
||||
# TOKEN="your_api_token_here"
|
||||
# ensure to have set TOKEN to a valid value before running
|
||||
# ideally add this to an .envrc file and source it
|
||||
# only the admin user can create entries so this should
|
||||
# fail unless .env has ADMIN_EMAIL set to the user that
|
||||
# the token belongs to
|
||||
|
||||
URL='http://127.0.0.1:8000/api/entries'
|
||||
|
||||
curl -X POST \
|
||||
-H "Authorization: Bearer $TOKEN" \
|
||||
-H "Accept: application/json" \
|
||||
-H "Content-Type: application/json" \
|
||||
-d '{
|
||||
"title": "Yet Another New Entry Title",
|
||||
"content": "This is the content yet again of the new entry."
|
||||
}' \
|
||||
$URL
|
||||
16
cmd/curl_post_entry_anon.sh
Executable file
16
cmd/curl_post_entry_anon.sh
Executable file
|
|
@ -0,0 +1,16 @@
|
|||
#!/usr/bin/env bash
|
||||
|
||||
# this should fail as no token is provided
|
||||
# user is not authenticated
|
||||
# no token has been granted
|
||||
|
||||
URL='http://127.0.0.1:8000/api/entries'
|
||||
|
||||
curl -X POST \
|
||||
-H "Accept: application/json" \
|
||||
-H "Content-Type: application/json" \
|
||||
-d '{
|
||||
"title": "Yet Another New Entry Title",
|
||||
"content": "This is the content yet again of the new entry."
|
||||
}' \
|
||||
$URL
|
||||
Loading…
Add table
Add a link
Reference in a new issue