Added json_api sample
This commit is contained in:
parent
328629b6f4
commit
d0c87f23d1
2 changed files with 18 additions and 1 deletions
|
@ -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
|
||||
|
|
9
samples/json_api.cr
Normal file
9
samples/json_api.cr
Normal file
|
@ -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
|
Loading…
Reference in a new issue