Y
Y
Yunique2018-08-09 17:21:42
API
Yunique, 2018-08-09 17:21:42

How to write an HTTP request to a third party API on rails?

I was faced with such a task, to write a rake-task with an HTTP request (POST) to an external API. Preferably using rest-client
Perhaps someone knows some thread of an article or a screencast where they do something similar, or somewhere there is a similar example of such actions.
Thank you in advance.

Answer the question

In order to leave comments, you need to log in

1 answer(s)
R
Roman Mirilaczvili, 2018-08-09
@Yunique33

It is important to be able to use the Internet search and gem documentation. In addition, it is worth learning English.
In the console or using the task scheduler using OS tools, you can call your task from the project.
When a task is started, code (which needs to be written) can be executed that accesses a third-party server via the HTTP API. It is also important to check the error return code.
How to write tasks is described here: https://railsguides.net/how-to-generate-rake-task/
The link you provided https://github.com/rest-client/rest-client has all the examples:

>> response = RestClient.get 'http://example.com/resource'
=> <RestClient::Response 200 "<!doctype h...">
>> response.code
=> 200
>> response.cookies
=> {"Foo"=>"BAR", "QUUX"=>"QUUUUX"}
>> response.headers
=> {:content_type=>"text/html; charset=utf-8", :cache_control=>"private" ... }
>> response.body
=> "<!doctype html>\n<html>\n<head>\n    <title>Example Domain</title>\n\n ..."

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question