From bbe22e96e3875a0f06b5476abfa295b277cdbe6b Mon Sep 17 00:00:00 2001 From: Sdogruyol Date: Fri, 6 Nov 2015 20:49:08 +0200 Subject: [PATCH] Added JSON payload retrieval to README --- README.md | 10 ++++++++++ 1 file changed, 10 insertions(+) diff --git a/README.md b/README.md index b4d07aa..787b106 100644 --- a/README.md +++ b/README.md @@ -81,6 +81,16 @@ Accessing the environment (query params, body, content_type, headers, status_cod height = env.params["height"] end + # Easily access JSON payload from the params. + # The request content type needs to be application/json + # The payload + # {"name": "Serdar", "likes": ["Ruby", "Crystal"]} + post "/json_params" do |env| + name = env.params["name"] as String + likes = env.params["likes"] as Array + "#{name} likes #{likes.each.join(',')}" + end + # Set the content as application/json and return JSON get "/user.json" do |env| kemal = {name: "Kemal", language: "Crystal"}