rails new notebook-api --api
rails g scaffold Contact name:string email:string birthdate:date
rails db:migrate
# See all contacts
curl http://127.0.0.1:3000/contacts
# See the contact 1
curl http://127.0.0.1:3000/contacts/1
# See the contact 1 with verbose
curl http://127.0.0.1:3000/contacts/1 -v
# See the contact 1 with verbose use verb
curl http://127.0.0.1:3000/contacts/1 -v -X GET
# Create a new contact use verb POST in json
curl http://127.0.0.1:3000/contacts -i -v -X POST -H "Content-Type: application/json" -d '{"name": "alanalves","email": "alanalves@empresa.corp"}'
# Updating the contact use verb PATCH
curl http://127.0.0.1:3000/contacts/101 -i -v -X PATCH -H "Content-Type: application/json" -d '{"name": "alansilva","email": "alan@empresa.corp"}'
# See new contact 101
curl http://127.0.0.1:3000/contacts/101
# Deleting a contact use verb DELETE
curl http://127.0.0.1:3000/contacts/101 -i -v -X DELETE
rails g scaffold Kind description:string
rails db:migrate
rails g migration add_kind_to_contact kind:references
rails db:migrate
rails db:drop db:create db:migrate dev:setup
##
curl http://127.0.0.1:3000/contacts -i -v -X POST -H "Content-Type: application/json" -d '{ "name": "alanalves","email": "alanalves@empresa.corp", "birthdate":"2002-05-27", "kind_id":3 }'
##
curl http://127.0.0.1:3000/contacts/101 -i -v
rails g model Phone number:string contact:references
vim lib/tasks/dev.rake
rails db:drop db:create db:migrate dev:setup --trace
rails g serializer contact
rails g serializer kind
curl http://127.0.0.1:3000/contacts/4 -H "Accept: application/vnd.api+json" -v
curl http://127.0.0.1:3000/contacts -H "Accept: application/vnd.api+json" -v
curl http://127.0.0.1:3000/contacts -H "Accept: application/vnd.api+json" -v
curl http://localhost:3000/contacts/4/relationships/kind -H "Accept: application/vnd.api+json"
curl http://localhost:3000/contacts/100/address -X DELETE -H "Accept: application/vnd.api+json"
curl http://localhost:3000/contacts/100/address -X DELETE -H "Accept: application/vnd.api+json"
curl http://localhost:3000/contacts/100/address -H "Accept: application/vnd.api+json"
curl http://localhost:3000/contacts/99/phones -H "Accept: application/vnd.api+json"
curl http://localhost:3000/kinds -v -I -H "Accept: application/vnd.api+json" -u alan:secret
curl http://localhost:3000/kinds -v -I -H "Accept: application/vnd.api+json" -u alan:secreterror
curl http://localhost:3000/kinds -v -I -H "Accept: application/vnd.api+json" -u alan:secret
curl http://localhost:3000/kinds -v -I -H "Accept: application/vnd.api+json" -u alan:secret --digest
curl http://localhost:3000/kinds -H "Accept: application/vnd.api+json" -H "Authorization: Token secret123456"
curl http://localhost:3000/kinds -v -I -H "Accept: application/vnd.api+json" -H "Authorization: Token secret123456"
curl http://localhost:3000/auth -X POST -H "Accept: application/vnd.api+json" -H "Content-Type: application/json" -d '{ "email": "alanlogin@empresa.corp", "password": "12345678", "password_confirmation": "12345678" }'
#
# Result from command curl
# {"status":"success","data":{"email":"alanlogin@empresa.corp","uid":"alanlogin@empresa.corp","id":1,"provider":"email","allow_password_change":false,"name":null,"nickname":null,"image":null,"created_at":"2021-06-06T13:04:28.277Z","updated_at":"2021-06-06T13:04:28.480Z","type":"user"}}%
curl http://localhost:3000/auth/sign_in -X POST -H "Accept: application/vnd.api+json" -H "Content-Type: application/json" -d '{ "email": "alanlogin@empresa.corp", "password": "12345678" }'
#
# Result from command curl
# {"data":{"email":"alanlogin@empresa.corp","uid":"alanlogin@empresa.corp","id":1,"provider":"email","allow_password_change":false,"name":null,"nickname":null,"image":null,"type":"user"}}%
curl http://localhost:3000/kinds -H "Accept: application/vnd.api+json"
#
#
# {"errors":["Para continuar, faça login ou registre-se."]}%
# Use -i and -v on sign_in
curl http://localhost:3000/auth/sign_in -i -v -X POST -H "Accept: application/vnd.api+json" -H "Content-Type: application/json" -d '{ "email": "alanlogin@empresa.corp", "password": "12345678" }'
# Use on header access-token, client, uid and too option -v
curl http://localhost:3000/kinds -H "Accept: application/vnd.api+json" -H "access-token: 66x5vOVQshrpPIuUUOp8cA" -H "client: chgwxR-fFXfvjRd53MbsVQ" -H "uid: alanlogin@empresa.corp" -v
* Trying ::1...
* TCP_NODELAY set
* Connected to localhost (::1) port 3000 (#0)
> GET /kinds HTTP/1.1
> Host: localhost:3000
> User-Agent: curl/7.64.1
> Accept: application/vnd.api+json
> access-token: 66x5vOVQshrpPIuUUOp8cA
> client: chgwxR-fFXfvjRd53MbsVQ
> uid: alanlogin@empresa.corp
>
< HTTP/1.1 200 OK
< X-Frame-Options: SAMEORIGIN
< X-XSS-Protection: 1; mode=block
< X-Content-Type-Options: nosniff
< X-Download-Options: noopen
< X-Permitted-Cross-Domain-Policies: none
< Referrer-Policy: strict-origin-when-cross-origin
< Content-Type: application/vnd.api+json; charset=utf-8
< Vary: Accept, Origin
< access-token: 0ZpcTagQBtujJ8bMISw4oQ
< token-type: Bearer
< client: chgwxR-fFXfvjRd53MbsVQ
< expiry: 1624196424
< uid: alanlogin@empresa.corp
< ETag: W/"03d9aa24cc1f04b7fcea4e30d530f73c"
< Cache-Control: max-age=0, private, must-revalidate
< X-Request-Id: 22834807-98bf-44c4-8458-0aefe43cafbe
< X-Runtime: 0.289410
< Transfer-Encoding: chunked
<
* Connection #0 to host localhost left intact
{"data":[{"id":"1","type":"kinds","attributes":{"description":"Friend"}},{"id":"2","type":"kinds","attributes":{"description":"Commercial"}},{"id":"3","type":"kinds","attributes":{"description":"Known"}}]}* Closing connection 0
You saw that the token return data are different and if you look at the terminal, an update has occurred.
10:40:24 web.1 | User Update (0.5ms) UPDATE "users" SET "tokens" =?, "updated_at" = ? WHERE "users"."id" = ? ...
curl http://localhost:3000/contacts\?version\=1 -H "Accept: application/vnd.api+json"
curl http://localhost:3000/contacts\?version\=2 -H "Accept: application/vnd.api+json"
This README would normally document whatever steps are necessary to get the application up and running.
Things you may want to cover:
-
Ruby version
-
System dependencies
-
Configuration
-
Database creation
-
Database initialization
-
How to run the test suite
-
Services (job queues, cache servers, search engines, etc.)
-
Deployment instructions
-
...