Aprendendo a fazer uma API
rails new estudo_api --api -d mysql
rails rails g scaffold Usuario nome email senha
rails db:create db:migrate
- GET
http://localhost:3000/api/v1/usuarios
- POST
http://localhost:3000/api/v1/usuarios
- PUT
http://localhost:3000/api/v1/usuarios/id
- DELETE
http://localhost:3000/api/v1/usuarios/id
namespace :api do
namespace :v1 do
module Api
module V1
class UsuariosController < ApplicationController [...]
- JSON (post):
{
"nome": "Isadora",
"email": "meuemail@example.com",
"senha": "minhasenha123"
}
201 created
{
"id": 1,
"nome": "Isadora",
"email": "meuemail@example.com",
"senha": "minhasenha123",
"created_at": "2024-04-10T20:19:12.302Z",
"updated_at": "2024-04-10T20:19:12.302Z"
}