Giter Site home page Giter Site logo

batch_api's People

Contributors

arsduo avatar dlackty avatar dwaller avatar pbendersky avatar pmq20 avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

batch_api's Issues

Rails 4 and Ruby 2.1 issue.

What about Rails 4 and Ruby 2.1. When i'am implement batch_api and rails 4 app. PUT method in ops[] response 404, GET and POST method - ok.
my query:

{"ops":
[
{"method": "PUT",
"url": "/api/stock_locations/1/stock_items/1",
"params":{"stock_item":{"count_on_hand":"2"}}
},
{"method": "get","url": "/api/stock_locations/1/stock_items/1"}
],
"sequential": "true"}

UPDATED:
params on rails controller after batch_api
{"stock_item"=>{"count_on_hand"=>"2"}}

params on rails controller after direct request
{"stock_item"=>{"count_on_hand"=>"2"},
"format"=>"json",
"action"=>"update",
"controller"=>"spree/api/stock_items",
"stock_location_id"=>"1",
"id"=>"2"}

Error reporting middleware

There should be an integration with airbrake if it's available, so you get errors reported. Can we use it as is, or do we need special code?

404 when using query string

I am using batch_api with a Grape API in a Rails app. I found that all batch requests processed normally except for those using query string parameters. For example, this request would work:

{
  "ops": [
    {"method": "get", "url": "/api/v1/model"}
  ],
  "sequential": true
}

The response:

{
  "results": [
    {
      "body": "[{:one=>1}]",
      "headers": {
        "Content-Type": "application/json"
      },
      "status": 200
    }
  ]
}

The same request with a query string fails:

{
  "ops": [
    {"method": "get", "url": "/api/v1/model?per_page=5"}
  ],
  "sequential": true
}

Returns:

{
  "results": [
    {
      "body": "Not Found",
      "headers": {
        "X-Cascade": "pass"
      },
      "status": 404
    }
  ]
}

This was true whether the query string had values or not, i.e., /api/v1/model? also failed without any parameters.

I inspected the Rack env variable in a batch request with a query string. env['PATH_INFO'] = '/api/v1/model?per_page=5' is the value, and this value does not work. If there is a query string appended to PATH_INFO then the call will fail. When I reset PATH_INFO to remove the query string the batch call completed successfully.

The other difference I saw was that rack.request.query_hash was empty, but this didn't appear to impact the request.

This looks like it can be fixed by setting ORIGINAL_FULLPATH and PATH_INFO separately in https://github.com/arsduo/batch_api/blob/master/lib/batch_api/operation/rack.rb#L65.

@env["ORIGINAL_FULLPATH"] = @url
@env["PATH_INFO"] = @url.split('?').first

@arsduo Do you know if there are any unforeseen consequences from this change? Would you accept a PR for this issue?

Would you give me some examples of requests?

For example, I tried this request by reference to https://developers.facebook.com/docs/graph-api/making-multiple-requests/
curl -F 'ops=[{"method":"GET", "url":"/api/tags"},{"method":"GET", "url":"/api/notes"}]' -F 'sequential=1' http://localhost:3000/batch

Then, I got this error
"Only 50 operations can be submitted at once, 77 were provided"

By changing like this, it works well.

module BatchApi
  class Processor

    .....

    def process_ops
      ops = @request.params.delete("ops")
      ops = JSON.parse(ops) # ← json parse
      if !ops || ops.empty?
        raise Errors::NoOperationsError, "No operations provided"
      elsif ops.length > BatchApi.config.limit
        raise Errors::OperationLimitExceeded,
          "Only #{BatchApi.config.limit} operations can be submitted at once, " +
          "#{ops.length} were provided"
      else
        ops.map do |op|
          self.class.operation_klass.new(op, @env, @app)
        end
      end
    end

Sending a request by using jQuery post method to my rails app as below.

$.post('/batch',
{ops:[
    {method: "get", url: "/api/tags"},
    {method: "get", url: "/api/notes"}
  ],
  sequential: true
},
function(){
  console.log(arguments)
});

Then, I got this error
{"error":{"message":"can't convert String into Integer","backtrace":[" .... /batch_api/lib/batch_api/operation/rack.rb:16:in `[]' ...

By changing like this, it works well.

module BatchApi
  class Processor

    .....

    def process_ops
      ops = @request.params.delete("ops")
      if !ops || ops.empty?
        raise Errors::NoOperationsError, "No operations provided"
      elsif ops.length > BatchApi.config.limit
        raise Errors::OperationLimitExceeded,
          "Only #{BatchApi.config.limit} operations can be submitted at once, " +
          "#{ops.length} were provided"
      else
        ops.values.map do |op| # ← call values before map
          self.class.operation_klass.new(op, @env, @app)
        end
      end
    end

But it should work without any changes.
Would you give me some examples of requests?

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.