Sha256: 4c1ba876c1889ec4b95ca748df2a6ce5d53b011527787ffc030ee06227da6849

Contents?: true

Size: 1.01 KB

Versions: 14

Compression:

Stored size: 1.01 KB

Contents

# frozen_string_literal: true

require_relative 'application_api_client'

# An usage example of the `my_api_client`.
# See also: my_api/app/controllers/rest_controller.rb
class MyRestApiClient < ApplicationApiClient
  # GET rest
  def get_posts(order: :asc)
    order = :desc unless order == :asc
    query = { order: order }
    get 'rest', query: query, headers: headers
  end

  # GET rest/:id
  def get_post(id:)
    get "rest/#{id}", headers: headers
  end

  # POST rest
  def post_post(title:)
    body = { title: title }
    post 'rest', body: body, headers: headers
  end

  # PUT rest/:id
  def put_post(id:, title:)
    body = { title: title }
    put "rest/#{id}", body: body, headers: headers
  end

  # PATCH rest/:id
  def patch_post(id:, title:)
    body = { title: title }
    patch "rest/#{id}", body: body, headers: headers
  end

  # DELETE rest/:id
  def delete_post(id:)
    delete "rest/#{id}", headers: headers
  end

  private

  def headers
    { 'Content-Type': 'application/json;charset=UTF-8' }
  end
end

Version data entries

14 entries across 14 versions & 1 rubygems

Version Path
my_api_client-1.1.0 example/api_clients/my_rest_api_client.rb
my_api_client-1.0.0 example/api_clients/my_rest_api_client.rb
my_api_client-0.27.0 example/api_clients/my_rest_api_client.rb
my_api_client-0.26.0 example/api_clients/my_rest_api_client.rb
my_api_client-0.25.0 example/api_clients/my_rest_api_client.rb
my_api_client-0.24.0 example/api_clients/my_rest_api_client.rb
my_api_client-0.23.0 example/api_clients/my_rest_api_client.rb
my_api_client-0.22.0 example/api_clients/my_rest_api_client.rb
my_api_client-0.21.0 example/api_clients/my_rest_api_client.rb
my_api_client-0.20.0 example/api_clients/my_rest_api_client.rb
my_api_client-0.19.0 example/api_clients/my_rest_api_client.rb
my_api_client-0.18.0 example/api_clients/my_rest_api_client.rb
my_api_client-0.17.0 example/api_clients/my_rest_api_client.rb
my_api_client-0.16.1 example/api_clients/my_rest_api_client.rb