Skip to content

Commit

Permalink
Add json-post example. (#143)
Browse files Browse the repository at this point in the history
Co-authored-by: Kasper Lund <[email protected]>
  • Loading branch information
floitsch and kasperl authored Jun 21, 2024
1 parent dd1d9c0 commit 45724d7
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 0 deletions.
3 changes: 3 additions & 0 deletions examples/server.toit
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,9 @@ main:
</body>
</html>
"""
else if resource == "/post-json" and request.method == http.POST:
decoded := json.decode-stream request.body
print "Received JSON: $decoded"
else if resource == "/json":
writer.headers.set "Content-Type" "application/json"
writer.out.write
Expand Down
3 changes: 3 additions & 0 deletions src/server.toit
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,9 @@ main:
</body>
</html>
"""
else if resource == "/json" and request.method == http.POST:
decoded := json.decode-stream request.body
print "Received JSON: $decoded"
else:
writer.headers.set "Content-Type" "text/plain"
writer.write-headers 404
Expand Down

0 comments on commit 45724d7

Please sign in to comment.