shard-kemal/docs/json.md

17 lines
383 B
Markdown
Raw Normal View History

2015-12-04 11:54:12 +00:00
# Serving JSON API
2015-12-07 20:03:35 +00:00
You need to return a ```JSON``` object or need to convert the existing object via `to_json`.
2015-12-04 11:54:12 +00:00
```ruby
require "kemal"
require "json"
# You can easily access the context and set content_type like 'application/json'.
# Look how easy to build a JSON serving API.
get "/" do |env|
env.content_type = "application/json"
{name: "Serdar", age: 27}.to_json
end
```