Skip to content

Conversation

@frankywahl
Copy link

The Sawyer::Agent contains the base URL to hit. Let Saywer handle the
base URL (with the path beginning) to allow for other endpoints to be created that do not depend
on such a URL. This will open doors to implement the API against the OpenID specs from https://developer.okta.com/docs/reference/api/oidc/#composing-your-base-url.
As for example, it is not currently possible to do

headers = {
   # define me
}
client = Oktakit.new(api_endpoint: "http://okta-instance.okta.com")
client.post("/oauth2/default/v1/userinfo", headers: header)

as this will end up requesting http://okta-instance.okta.com/api/v1/oauth2/default/v1/userinfo

Here is an example illustrating the sawyer spec:

require "webmock"
require "webmock/rspec"
require "sawyer"

WebMock.enable!
include WebMock::API

describe Sawyer::Agent do
  describe "the base URL path" do
    it "is ignored on an abosulute path" do
      request = stub_request(:get, "http://api.example.com/bar")

      agent = described_class.new("http://api.example.com/foo")
      agent.call(:get, "/bar")
      expect(request).to have_been_made
    end

    it "is included on an relative path" do
      request = stub_request(:get, "http://api.example.com/foo/bar")

      agent = described_class.new("http://api.example.com/foo")
      agent.call(:get, "bar")
      expect(request).to have_been_made
    end

    it "is doesn't matter if the endpoint does not contain a path" do
      request = stub_request(:get, "http://api.example.com/bar")

      agent = described_class.new("http://api.example.com")
      agent.call(:get, "bar")
      expect(request).to have_been_made
    end
  end
end

The Sawyer::Agent contains the base URL to hit. Let Saywer handle the
base URL to allow for other endpoints to be created that do not depend
on such a URL.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant