Create Tokens
Add the standard HTTP method POST for the tokens controller in the API.
We'll cover the following...
We only need the POST
request for the tokens controller as we will not need to view, edit, or delete the tokens. Thus, we will just be working on the create
action.
Add routes
We will modify the route a little to respect the REST conventions. The config/routes.rb
should look like this:
Press + to interact
Rails.application.routes.draw donamespace :api, defaults: { format: :json } donamespace :v1 doresources :users, only: %i[show create update destroy]resources :tokens, only: [:create]endendend
Add tests
We will build functional tests before going any further. The desired behavior is as follows:
- The user receives a token if they send a valid email/password pair.
- Otherwise, the server responds