mirror of
https://gitea.invidious.io/iv-org/shard-kemal.git
synced 2024-08-15 00:53:36 +00:00
Create json.md
This commit is contained in:
parent
eb546315d1
commit
6c1dd90611
1 changed files with 16 additions and 0 deletions
16
docs/json.md
Normal file
16
docs/json.md
Normal file
|
@ -0,0 +1,16 @@
|
||||||
|
# Serving JSON API
|
||||||
|
|
||||||
|
Just use `to_json` method to return.
|
||||||
|
|
||||||
|
```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
|
||||||
|
|
||||||
|
```
|
Loading…
Reference in a new issue