Build a RESTful JSON API With Rails

Image for post
Image for post
Rails API

Getting Started

rails new my_api --api -T

Rack CORS

#Use Rack CORS for handling Cross-Origin Resource Sharing (CORS), making cross-origin AJAX possible
gem ‘rack-cors’, :require => ‘rack/cors’

Models


rails g model User username:string password:string
rails db:migrate

Serializer

gem ‘active_model_serializers’
rails g serializer user

Controllers


rails g controller api/v1/Users

Namespaced Routes

Seed Data


oliver = User.create( username: ‘Oliver’, password: ‘password’ )

I am a Full Stack software engineer that enjoys problem solving and can't wait to learn more. Hard work and dedication shape my work ethic.

Get the Medium app

A button that says 'Download on the App Store', and if clicked it will lead you to the iOS App store
A button that says 'Get it on, Google Play', and if clicked it will lead you to the Google Play store