grape-api

Ember.js POST requests return 400 from the server (Grape API) but are stored successfully into local storage

假如想象 提交于 2019-12-13 14:30:55
问题 I've been trying to get a simple Ember.js application to post to a Grape API backend for hours now, but I cannot seem to get it to work. I know the API works because I can post new records to it through the Swagger documentation, and they are persisted. I know the API and Ember are talking just fine because I can get all records from the server and interact with them on the page, and I know that Ember is working fine in a vacuum because my records are persisted to local storage. However, I

What should the Content-Type be for a 4xx error without a body?

二次信任 提交于 2019-12-05 12:15:35
问题 Consider an HTTP request that gets the following response: 405 Method Not Allowed Content-Length: 0 What should the content-type of something like this be? Set to nothing? Not set? Set to text/plain or text/html 回答1: You haven't got any content, therefore I wouldn't set a Content-Type at all. If you find that causes problems to clients (which seems unlikely, to be honest), I'd probably go with text/plain - definitely not text/html , as your "empty content" is not an HTML document. 来源: https:/

How to allow Binary File download using GRAPE API

那年仲夏 提交于 2019-12-03 09:48:08
问题 I want to allow downloading a binary file (.p12 file) using ruby's Grape API. This is what I am trying. get '/download_file' do pkcs12 = generate_pkcsfile content_type('application/octet-stream') body(pkcs12.der) end The equivalent code using ActionController is begin pkcs12 = generate_pkcsfile send_data(pkcs12.der, :filename => 'filename.p12') end The problem is the file downloaded using the API seems to be a text file with a '\ufffd' prefix embedded for every character, whereas the file

How to split things up in a grape api app?

巧了我就是萌 提交于 2019-12-03 08:10:45
问题 In every examples I see, people only implement one giant api.rb file. Ex: intridea/grape bloudraak/grape-sample-blog-api djones/grape-goliath-example While this approach works fine as is, it can quickly become crowded and difficult to maintain so I would like to split things up on my app. For instance, I would like to split my entities from my resources, and then split up my resources between different files. For examples: app - api api.rb - entities - weblog.rb - post.rb - comment.rb -

How to allow Binary File download using GRAPE API

∥☆過路亽.° 提交于 2019-12-03 00:14:16
I want to allow downloading a binary file (.p12 file) using ruby's Grape API. This is what I am trying. get '/download_file' do pkcs12 = generate_pkcsfile content_type('application/octet-stream') body(pkcs12.der) end The equivalent code using ActionController is begin pkcs12 = generate_pkcsfile send_data(pkcs12.der, :filename => 'filename.p12') end The problem is the file downloaded using the API seems to be a text file with a '\ufffd' prefix embedded for every character, whereas the file downloaded using the browser seems to be binary file. How do I use the GRAPE API framework to allow

How to split things up in a grape api app?

点点圈 提交于 2019-12-02 20:52:35
In every examples I see, people only implement one giant api.rb file. Ex: intridea/grape bloudraak/grape-sample-blog-api djones/grape-goliath-example While this approach works fine as is, it can quickly become crowded and difficult to maintain so I would like to split things up on my app. For instance, I would like to split my entities from my resources, and then split up my resources between different files. For examples: app - api api.rb - entities - weblog.rb - post.rb - comment.rb - resources - weblog.rb - post.rb - comment.rb Now, api.rb would be something like: require 'grape' module

What is the difference between `try` and `&.` (safe navigation operator) in Ruby

依然范特西╮ 提交于 2019-11-27 15:45:48
问题 Here is my code: class Order < Grape::Entity expose :id { |order, options| order.id.obfuscate } expose :time_left_to_review do |order, options| byebug order&.time_left_to_review # ERROR end expose :created_at { |order, options| order.last_transition.created_at } end # NoMethodError Exception: undefined method `time_left_to_review' for #<Order:0x007f83b9efc970> I thought &. is a shortcut for .try but I guess I was wrong. May someone point me to the right direction regarding what I am missing?