ruby - Sinatra + Redis and POST request with cURL -


i learning sinatra , redis building small url shortener. here post route:

helpers  include rack::utils  alias_method :h, :escape_html   def random_string(length)   rand(36**length).to_s(36)  end end  post '/'  if params[:url].present?  content_type :json  @shortcode = random_string 5  short_url = redis.setnx "links:#{@shortcode}", params[:url]  short_url.to_json  end end 

this post method take long url input , generate short 1 output in json format.

but, when try curl using

curl -h "content-type: application/json" -x post -d '{"url": "http://mywebsite.com"}' http://localhost:4567 

it fails , get

nomethoderror: undefined method `present?' nil:nilclass. 

any hint?


Comments

Popular posts from this blog

aws api gateway - SerializationException in posting new Records via Dynamodb Proxy Service in API -

asp.net - Problems sending emails from forum -