Rails 7 #130 API CRUD endpoints

08/05/2023 (12 months ago)
rest api api development rails api api crud

Create an API Controller where you can LIST, SHOW, CREATE, UPDATE, DESTROY records.

Episode source code: https://github.com/corsego/130-api-crud-endpoints/commit/de101248398714ec367cf3c4dfad7e95c8373d4f
Based on this blogpost: https://blog.corsego.com/rails-api-bearer-authentication

0:00 Recap of what we already have
2:00 scaffold Posts, belong to user
3:45 WTF Format JSON
6:08 cURL request to access posts
7:07 Access Posts controller within our API
11:42 API controller authorization - user can access only his own posts
13:30 fix ActiveRecord::RecordNotFound error
14:59 CREATE via API, fix InvalidAuthenticityToken
16:40 UPDATE via API. Importance of strong params
18:17 DESTROY via API
19:20 cleanup API controller
19:36 summary

Sign in to join the conversation