开发者

API: Is it better to have a slower, conventient API implementation or a faster, more complex one?

开发者 https://www.devze.com 2023-02-15 04:34 出处:网络
I am using Ruby on Rails 3 and I am developing API for my applications. I have a web client app that make HTTP requests to a web server app. However the web application handles incoming request in th

I am using Ruby on Rails 3 and I am developing API for my applications.

I have a web client app that make HTTP requests to a web server app. However the web application handles incoming request in the controller and responds like this:

respond_to do |format|
  format.html {redirect_to @account}
  ...
  format.json {
    render :json => @account.to开发者_运维百科_json, :status => 200
  }
  format.xml {
    render :xml => @account.to_xml, :status => 200
  }
end

At this time I don't use Rack middlewares because it is very "convenient" to respond using respond_to, and you don't have to change anything more in your application other than the controller. Anyway, I know that using middleware is faster in responding than the above approach, but I should implement responses for every HTTP request, maybe intercepting them URI.

What do you advice about? It is better "convenience" and "slowness" (like the code above) or "complexity" and "fastest"?


Premature optimization is the root of all evil. If the code is fast enough for your purposes using the design that you prefer, keep using it. If you find that it's not fast enough, then you can look at options for speeding it up.

0

精彩评论

暂无评论...
验证码 换一张
取 消