Y
Y
yesterday8s2017-09-20 13:20:23
Ruby on Rails
yesterday8s, 2017-09-20 13:20:23

How to use 3rd party rest api in rails?

I'm trying to use some api on the page.
I want to send a post to site/api/token
with login and password parameters
, the response should be json with a token
that can be used in other get requests to this host

require 'net/http'
require 'uri'
uri = URI.parse('http://site/api/token')
response = Net::HTTP.post_form(uri, {'User'=>'myname', 'Pass'=>'mypass'})

I don’t know how to save the token and am I writing correctly?
does the version of rails matter here?

Answer the question

In order to leave comments, you need to log in

2 answer(s)
A
Andrey Andreev, 2017-09-20
@b0nn1e

If it works, then it's correct.
No.

Y
yesterday8s, 2017-09-21
@yesterday8s

In the production logs I do not see any records of successful or unsuccessful requests
. And how to save the incoming token?
like:
@token = JSON.parse(res.body)

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question