Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

v1 in URL #83

Open
johnrees opened this issue Nov 28, 2013 · 3 comments
Open

v1 in URL #83

johnrees opened this issue Nov 28, 2013 · 3 comments
Assignees
Milestone

Comments

@johnrees
Copy link
Contributor

Apologies if I'm missing something extremely obvious. I've dug through https://github.com/filtersquad/rocket_pants/blob/master/lib/rocket_pants/routing.rb and tried using required_prefix, optional_prefix in my routes.rb to no avail.

Purely for vanity reasons I was hoping to have urls like https://api.mydomain.com/v1/objects following the docs I've got to https://api.mydomain.com/1/objects and it works great. So my question is, is there a simple way to add the 'v'?

  constraints subdomain: 'api' do
    get '/' => 'static#api'
    api versions: 1, module: "api/v1" do
      resources :labs, only: [:index]
    end
  end
@Sutto
Copy link
Owner

Sutto commented Nov 29, 2013

Hey John,

In theory adding require_prefix: 'v' to the api call in the router should do exactly that - I'll take a look and see if I can recreate it locally / work out what's going wrong.

@Sutto
Copy link
Owner

Sutto commented Nov 29, 2013

Ok, so the main bug that remains is in route generation - I have it working locally, but the issue is it unpacks the version from v1 to 1 (the numeric version), and then route generation fails - for requires_prefix at least.

This is one of the issues with the named version stuff, and needs a bit more work to get to the root of the issue - For the moment, you should be able to use require_prefix and explicitly pass in version: 'v1' when you generate the url.

@ghost ghost assigned Sutto Dec 13, 2013
@SirRawlins
Copy link

@johnrees I've been playing with this versioning prefix myself this morning and seem to have it running quite nicely.

As suggested by @Sutto you need to add the prefix definition to your api call in your routes. You have two options, a required or an optional prefix, however the call in the routes definition uses require_prefix or allow_prefix.

constraints subdomain: 'api' do
    get '/' => 'static#api'

    api versions: 1, module: "api/v1", allow_prefix: "v" do
        resources :labs, only: [:index]
    end
end

As a side note, if you have any routing specs in place for your API you'll need to add:

:rp_prefix => { "text" => "v", "required" => false }

to the expected request parameters for the route once you've enabled to the prefix, and also change your expected "version" request parameter from 1 to v1.

Hope this helps.

Robert

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

No branches or pull requests

3 participants