From d0c87f23d19697805f27163e2e2b2e48548cb561 Mon Sep 17 00:00:00 2001 From: Sdogruyol Date: Fri, 23 Oct 2015 22:25:46 +0300 Subject: [PATCH] Added json_api sample --- samples/hello_world.cr | 10 +++++++++- samples/json_api.cr | 9 +++++++++ 2 files changed, 18 insertions(+), 1 deletion(-) create mode 100644 samples/json_api.cr diff --git a/samples/hello_world.cr b/samples/hello_world.cr index a4366eb..147c1d0 100644 --- a/samples/hello_world.cr +++ b/samples/hello_world.cr @@ -1,5 +1,13 @@ require "kemal" +# Set root. If not specified the default content_type is 'text' get "/" do - "Hello World!" + "Hello Kemal!" +end + +# You can easily access the environment and set content_type like 'application/json'. +# Look how easy to build a JSON serving API. +get "/user.json" do |env| + env.response.content_type = "application/json" + {name: "Serdar", age: 27}.to_json end diff --git a/samples/json_api.cr b/samples/json_api.cr new file mode 100644 index 0000000..098b67d --- /dev/null +++ b/samples/json_api.cr @@ -0,0 +1,9 @@ +require "kemal" +require "json" + +# You can easily access the environment and set content_type like 'application/json'. +# Look how easy to build a JSON serving API. +get "/" do |env| + env.response.content_type = "application/json" + {name: "Serdar", age: 27}.to_json +end