Git Product home page Git Product logo

Comments (20)

igrigorik avatar igrigorik commented on June 16, 2024

cc: @joshbuddy

from goliath.

joshbuddy avatar joshbuddy commented on June 16, 2024

I'll take a look at this tonight..

from goliath.

mando avatar mando commented on June 16, 2024

@joshbuddy - I'm the guy that originally reported this issue. If you want to do some remote pairing, that would be super-rad :).

from goliath.

cowboyd avatar cowboyd commented on June 16, 2024

Any updates on this? We need to come up with some sort of workaround for our current release, and ideally it will look somewhat like the eventual solution.

One answer is to mount your API class directly on the route, and let it manage the instantiation of the API instance. e.g.

get '/', SomeApi

vs

get '/' do
  run SomeApi.new
end

from goliath.

igrigorik avatar igrigorik commented on June 16, 2024

Sorry haven't had a chance to dig in, not sure about @joshbuddy either. I think both of the above examples should be equivalent..

from goliath.

joshbuddy avatar joshbuddy commented on June 16, 2024

I really am hoping to look at this tonight. Sorry for the delay.

from goliath.

mikehale avatar mikehale commented on June 16, 2024

+1 for fixing this.

from goliath.

paneq avatar paneq commented on June 16, 2024

+2

from goliath.

joshbuddy avatar joshbuddy commented on June 16, 2024

Fixed in 740b601

from goliath.

koudelka avatar koudelka commented on June 16, 2024

Is the fix breaking with_api testing? As far as I can tell, on_header is no longer being called.

from goliath.

joshbuddy avatar joshbuddy commented on June 16, 2024

Yeah, I've broken something ... I will get it sorted out tonight. Either, I'll cut a branch or get everything passing nicely.

from goliath.

joshbuddy avatar joshbuddy commented on June 16, 2024

Okay, I've had to break the API slightly. My commit is here: 6c30768

The main difference is, if you want to use the on_* methods and mapping, you have to supply the class of the api on the mapping method. So, for the async test, you need to say:

class Test < Goliath::API
  put '/async', AsyncUpload
end

Thoughts anyone?

from goliath.

igrigorik avatar igrigorik commented on June 16, 2024

So, the only change with that is that you don't need to explicitly specify the run ... correct? If so, I actually like this new API much better.

from goliath.

igrigorik avatar igrigorik commented on June 16, 2024

Hmm, question.. with that new API, how do we inject middleware for that endpoint? ex:

  map "/hello_world" do
    use ::Rack::ContentLength
    run HelloWorld.new
  end

from goliath.

koudelka avatar koudelka commented on June 16, 2024

Would this fix break the neat bit in examples/rack_routes.rb, too?

map "/:number", :number => /\d+/ do
  if params[:number].to_i > 100
    run BigNumber.new
  else
    run HelloNumber.new
  end
end

from goliath.

joshbuddy avatar joshbuddy commented on June 16, 2024

@igrigorik: This example would still work as is. The only difference is if you want the on_* handlers to work, you have to supply the class and not use the run command at the end. So, you could also have:

map "/hello_world", HelloWorld do
  use ::Rack::ContentLength
end

@koudelka This example would work normally. This is kind of rabbit hole we've gotten into with this api though. I think the ultimate solution is to build the event handling in in a more clever way. Currently there is a "tacked on" feeling to the whole thing, but I think this is reasonable for now.

from goliath.

cowboyd avatar cowboyd commented on June 16, 2024

I, for one, am fine with this slight asymmetry (see my initial comment)

from goliath.

joshbuddy avatar joshbuddy commented on June 16, 2024

Well, I'm gonna close this issue, and think about writing a better API another day. I have some ideas of how this would look, so, off to another branch to work on this.

from goliath.

radsaq avatar radsaq commented on June 16, 2024

And of course routing is also asymmetric in that passing the API class to map causes middleware to be inherited.

from goliath.

igrigorik avatar igrigorik commented on June 16, 2024

@joshbuddy: Ah, cool, that makes sense.. and works for me, I think. Curious to see what you have in mind for the alternative API.

For sanity, we should still add an integration spec to cover this use case. (and update the routing examples)

from goliath.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.