Skip to main content

Build REST API with Devise

Rails • Asked by Oluwatosin Ekolie

Hi Guys, I've been struggling building an API for an iOS App to communicate with my Rails Web App. For authentication, I'm using Devise.

How do I create, update and delete a user through the API?

I have create the route:

namespace :api, defaults: {format: :json} do
namespace :v1 do
devise_scope :user do
post "/", :to => 'sessions#create'
delete "/logout", :to => 'session#destroy'

This is where I'm stuck

I think you can just simply make a POST to the same url as the sign up form normally which is /users. Same with PUT and DELETE but for logging in and out, you want to POST and DELETE to /sessions because that's a separate controller.

Login or Create An Account to join the conversation.

Subscribe to the newsletter

Join 27,623+ developers who get early access to new screencasts, articles, guides, updates, and more.

    By clicking this button, you agree to the GoRails Terms of Service and Privacy Policy.

    More of a social being? We're also on Twitter and YouTube.