batch_api
batch_api copied to clipboard
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?
I'm having this exact same issue with a small sinatra app. It seems the middleware is coercing the arrays into hashes.
For reference: https://github.com/jetaggart/batch-api-example
This is how I'm trying to make a request: https://github.com/jetaggart/batch-api-example/blob/master/public/batch.js#L31-L40
I'm doing this same thing. Was there a solution for you guys?
I'm having this same problem. It's quite concerning to me that there hasn't been any updates here since Dec, 2013. Is this project being maintained/supported?
@jetaggart what did you end up doing? Are you still using this gem?
I opened a pull request for the fix described by @kissrobber
It's been so long I don't even remember. I don't use this gem.