mirror of
https://gitea.invidious.io/iv-org/shard-kemal.git
synced 2024-08-15 00:53:36 +00:00
Update environment documentation
This commit is contained in:
parent
a7cc498dca
commit
f82a57b2a4
1 changed files with 9 additions and 8 deletions
17
README.md
17
README.md
|
@ -63,9 +63,9 @@ In Kemal, a route is an HTTP method paired with a URL-matching pattern. Each rou
|
||||||
end
|
end
|
||||||
```
|
```
|
||||||
|
|
||||||
## Context
|
## Environment
|
||||||
|
|
||||||
Accessing the request environment (query params, body, headers e.g) is super easy. You can use the context returned from the block:
|
Accessing the environment (query params, body, content_type, headers, status_code) is super easy. You can use the environment returned from the block:
|
||||||
|
|
||||||
```ruby
|
```ruby
|
||||||
# Matches /hello/kemal
|
# Matches /hello/kemal
|
||||||
|
@ -79,18 +79,19 @@ Accessing the request environment (query params, body, headers e.g) is super eas
|
||||||
width = env.params["width"]
|
width = env.params["width"]
|
||||||
height = env.params["height"]
|
height = env.params["height"]
|
||||||
end
|
end
|
||||||
```
|
|
||||||
|
|
||||||
## Content Type
|
|
||||||
Kemal uses *text/html* as the default content type. You can change it via the context.
|
|
||||||
|
|
||||||
```ruby
|
|
||||||
# Set the content as application/json and return JSON
|
# Set the content as application/json and return JSON
|
||||||
get "/user.json" do |env|
|
get "/user.json" do |env|
|
||||||
kemal = {name: "Kemal", language: "Crystal"}
|
kemal = {name: "Kemal", language: "Crystal"}
|
||||||
env.set_content_type "application/json"
|
env.content_type = "application/json"
|
||||||
kemal.to_json
|
kemal.to_json
|
||||||
end
|
end
|
||||||
|
|
||||||
|
# Add headers to your response
|
||||||
|
get "/headers" do |env|
|
||||||
|
env.add_header "Accept-Language", "tr"
|
||||||
|
env.add_header "Authorization", "Token 12345"
|
||||||
|
end
|
||||||
```
|
```
|
||||||
|
|
||||||
## Thanks
|
## Thanks
|
||||||
|
|
Loading…
Reference in a new issue