json - Creating an Rails based API. A bit lost what to do after object is saved -
i'm creating rails based api manage sms subscriptions. there's subscriptions controller respond_to :html, :json, :xml , subscription model. both working fine.
when subscription made, user still needs confirm subscription entering pin on page sent phone, i'm thinking of confirms controller manage that.
i have few questions regarding how implement this.
(1) right approach or best practice after subscription made. show subscription object created (html, json or xml depending how created) , manage confirms controller separated action or should redirect confirmation controller instead?
i guess since api responds json , xml, not idea redirect other page/controller , better show object created?
(2) if case, i'm using cancan manage role abilities. since subscriptions belong user owner (the developer) doesn't need authenticated post (i know who's user owner associated because of combination of keyword/shortcode given) , subscriptions can made surfer (no need authenticating before creating) how restrict created object surfer?
i guess if user logged in becomes easy show object him because owner how regular surfers created object , not need authenticate?
i'm not having way connect surfer object restrict ability it.
(3) idea show object after created regular surfer? may think may not relevant when developer doing through json api itself?
the subscription model simple, works this
$ curl http://mysite.com/subscriptions \ -d shortcode=7889 \ -d keyword=keyword \ -d phone=6895874587 \ -d country=us \
let me try attack 1 one:)
after record created practice return object if supported status code, ie if record created should return object along 200 status code. keep in mind status codes dont allow body, ie 201. modern http clients suport redirects still keep in 2 separate actions
in still idea authenticate user since want prevent 1 user posting on behalf of user. regardless if can determine user analyzing parameters can tie subscription ex:
@user=user.find_by_phone(params[:phone]) @subscribtion = @user.subscribtions.build(params)
yes,its idea return has been saved.
Comments
Post a Comment