Add the username to the JSON response to GET.

In addition to this, version the API with the classic
"api/v1" path.
main
absc 2024-08-07 22:10:45 +00:00
parent df09a192b0
commit ceea61c1ed
2 changed files with 6 additions and 6 deletions

View File

@ -40,7 +40,7 @@ start(_Type, StartArgs) ->
Dispatch = cowboy_router:compile([ Dispatch = cowboy_router:compile([
{'_', [ {'_', [
{"/user/:username", dudeswave_user_handler, #{bucket => ?USERSBUCK, {"/api/v1/user/:username", dudeswave_user_handler, #{bucket => ?USERSBUCK,
cookies => ?COOKIESBUCK}}, cookies => ?COOKIESBUCK}},
{"/", dudeswave_handler, #{bucket => ?APPBUCK}} {"/", dudeswave_handler, #{bucket => ?APPBUCK}}
]} ]}

View File

@ -17,14 +17,13 @@
-moduledoc """ -moduledoc """
JSON API to manage users. JSON API to manage users.
The username should be passed as one of the tokens of the request path, like The username should be passed as the last token in the request, like:
``` ```
/user/foo /user/foo
/user/foo/details
``` ```
However, the first form is preferred. Where `foo` is the actual username.
The user parameter must be called `username` as this module expects it The user parameter must be called `username` as this module expects it
in order to work properly. All the requests must be done with a valid in order to work properly. All the requests must be done with a valid
@ -63,6 +62,7 @@ GET /user/:username
``` ```
{ {
"user" : "foo",
"email": "foo@example.com", "email": "foo@example.com",
"description": "A wonderful user", "description": "A wonderful user",
"name": "Fantastic Foo" "name": "Fantastic Foo"
@ -110,7 +110,6 @@ DELETE /user/:username
- 202 Accepted - 202 Accepted
- 404 Not Found - 404 Not Found
""". """.
-behaviour(cowboy_handler). -behaviour(cowboy_handler).
@ -243,8 +242,9 @@ modify_user(Req, State) ->
user_details(Req, State) -> user_details(Req, State) ->
#{details := Details} = State, #{details := Details} = State,
Data = Details#{user => cowboy_req:binding(username, Req)},
{iolist_to_binary(json:encode(Details)), Req, State}. {iolist_to_binary(json:encode(Data)), Req, State}.
% %
% gen_server callbacks % gen_server callbacks