Create an user's referral. It'll return the referral id, which is supposed to be used for assembling and providing the user with the URL they must share with their friends.
Request:
curl -i -XPOST -H 'Content-Type: application/json' localhost:3000/referrals -d '{
"user_id": 1
}'
Response:
HTTP/1.1 201 Created
{"referral":{"id":2}}
We return 422 with a message informing what's the expected request body.
We return 404 and a proper error message instead of unprocessable entity so whoever is using this endpoint can have a clearer idea of what's going on.
This is not meant to be an user authentication and / or authorization service but one for handling only user referrals instead. We have an users table for the sake of keeping the users' credits.
The users endpoints allows other architectural components to inform the event of an user signing up -- with or without an attached referral.
Create a new user. It'll apply credits policies according to the presence of the referral id within the request params.
Request:
curl -XPOST -H 'Content-Type: application/json' localhost:3000/users -d '{
"user": { "name": "Alice" },
"referral_id": 1
}'
Response:
HTTP/1.1 204 No Content
We return 422 with a message informing what's the expected request body.
- Ruby 2.6.6
- Bundler 2.1.4
$ bundle
$ bin/rake db:setup
Run with
$ bin/rspec