I made a rails API, so I will leave it as a memorandum. Next time I will try to introduce API documents such as swagger
Add --api to rails new
rails new rails-test-api --api
Generate CRUD This time I created a bulletin board CRUD
rails generate scaffold Board title:string text:string
rails db:create
rails db:migrate
Launch application
rails s
Connect to http: // localhost: 3000/boards
Hit POST with Curl where [] is displayed
curl -X POST -H "Content-Type: application/json" -d '{"title": "test", "text": "It's a test"}' http://localhost:3000/boards
Data is created when you connect to http: // localhost: 3000/boards again
[{"id":1,"title":"test","text":"It's a test","created_at":"2020-12-24T17:27:15.312Z","updated_at":"2020-12-24T17:27:15.312Z"}]
This completes
https://railsguides.jp/api_app.html https://qiita.com/hanata-el/items/d96d84d1889b495aca00
Recommended Posts