Class: Eli::RestApi

Inherits:
Object
  • Object
show all
Defined in:
lib/eli/rest_api.rb

Overview

Documentation for Eli::RestApi.

Thin wrapper around Faraday that mirrors the behaviour of the Elixir Req based client: it normalizes headers (always sending a JSON content type), encodes request bodies as JSON and appends params to the query string for the verbs that don't carry a body.

Defined Under Namespace

Classes: Response

Constant Summary collapse

JSON_CONTENT_TYPE =
"application/json"

Class Method Summary collapse

Class Method Details

.delete(url, options = {}) ⇒ Object

Delete.

Examples

Eli::RestApi.delete("/rest/your/endpoint", params: { foo: "bar" }, headers: { "token" => "A_TOKEN" })


71
72
73
# File 'lib/eli/rest_api.rb', line 71

def delete(url, options = {})
  request_with_query(:delete, url, options)
end

.get(url, options = {}) ⇒ Object

Get.

Examples

Eli::RestApi.get("/rest/your/endpoint", params: { foo: "bar" }, headers: { "token" => "A_TOKEN" })


53
54
55
# File 'lib/eli/rest_api.rb', line 53

def get(url, options = {})
  request_with_query(:get, url, options)
end

.head(url, options = {}) ⇒ Object

Head.

Examples

Eli::RestApi.head("/rest/your/endpoint", params: { foo: "bar" }, headers: { "token" => "A_TOKEN" })


62
63
64
# File 'lib/eli/rest_api.rb', line 62

def head(url, options = {})
  request_with_query(:head, url, options)
end

.patch(url, options = {}) ⇒ Object

Patch.

Examples

Eli::RestApi.patch("/rest/your/endpoint", params: { foo: "bar" }, headers: { "token" => "A_TOKEN" })


44
45
46
# File 'lib/eli/rest_api.rb', line 44

def patch(url, options = {})
  request_with_body(:patch, url, options)
end

.post(url, options = {}) ⇒ Object

Post.

Examples

Eli::RestApi.post("/rest/your/endpoint", params: { foo: "bar" }, headers: { "token" => "A_TOKEN" })


26
27
28
# File 'lib/eli/rest_api.rb', line 26

def post(url, options = {})
  request_with_body(:post, url, options)
end

.put(url, options = {}) ⇒ Object

Put.

Examples

Eli::RestApi.put("/rest/your/endpoint", params: { foo: "bar" }, headers: { "token" => "A_TOKEN" })


35
36
37
# File 'lib/eli/rest_api.rb', line 35

def put(url, options = {})
  request_with_body(:put, url, options)
end