I want to write a script which calls the REST API just like a URL such as:
Http: // localhost: 3000 / api / v1 / user / xyz If I open this URL in the browser, then it asks for a user email and password Once authenticated, it returns a JSON response with a User ID. I do not know how I should authenticate through the script. Can anyone suggest me?
This is what I started:
'rubygems' is required 'net / http' requires 'json' api_url = "http: / / LocalHost: 3000 / API / V1 / User / XIZ "reserve = net :: HTTP.get_response (URI.fr (API_RR)) data = JSN PRS (Response.Obs) field = data. Adds the data, data puts data .keys This is the authentication for the API:
before_filter: Authorize, except = & gt; [: Key] certify private def authenticate_or_request_with_http_basic do | Username, password | User = User.find_by_email (user name) if user & amp; Amp; User.valid_password? (Password) sign_in: user, user end and end How can I pass an email and password to prove this API so that I can get an "id" return ?
Works best for me as far as the APIs that should be in the documentation. You can always try in the IRB and see what is involved in the reaction.
No comments:
Post a Comment