mirror of
https://gitea.invidious.io/iv-org/shard-kemal.git
synced 2024-08-15 00:53:36 +00:00
16 lines
383 B
Markdown
16 lines
383 B
Markdown
# Serving JSON API
|
|
|
|
You need to return a ```JSON``` object or need to convert the existing object via `to_json`.
|
|
|
|
```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
|
|
|
|
```
|