mirror of
https://gitea.invidious.io/iv-org/shard-kemal.git
synced 2024-08-15 00:53:36 +00:00
Update
This commit is contained in:
parent
6896cb413a
commit
3a4f98d468
13 changed files with 58 additions and 83 deletions
|
@ -18,12 +18,12 @@ collections:
|
||||||
|
|
||||||
nav_bars:
|
nav_bars:
|
||||||
- title: "Documents"
|
- title: "Documents"
|
||||||
url: "/kemal/docs/getting_started"
|
url: "/kemal/docs/getting_started.html"
|
||||||
- title: "Blog"
|
- title: "Blog"
|
||||||
url: "/blog"
|
url: "/blog/"
|
||||||
- title: "Github"
|
- title: "Github"
|
||||||
url: "https://github.com/sdogruyol/kemal"
|
url: "https://github.com/sdogruyol/kemal"
|
||||||
|
|
||||||
examples:
|
examples:
|
||||||
- title: "How to connect to Database"
|
- title: "How to connect to Database"
|
||||||
url: https://github.com/sdogruyol/kemal-pg-sample
|
url: "https://github.com/sdogruyol/kemal-pg-sample"
|
||||||
|
|
|
@ -31,7 +31,6 @@ Kemal means *Mature, grown up* in Turkish.
|
||||||
- [Websockets](./websockets.md)
|
- [Websockets](./websockets.md)
|
||||||
- [Using Dynamic Views](./views.md)
|
- [Using Dynamic Views](./views.md)
|
||||||
- [HTTP Requests and Responses](./http-requests.md)
|
- [HTTP Requests and Responses](./http-requests.md)
|
||||||
- [Serving Static Files](./statics.md)
|
|
||||||
- [Serving JSON API](./json.md)
|
- [Serving JSON API](./json.md)
|
||||||
- [Middlewares](./middlewares.md)
|
- [Middlewares](./middlewares.md)
|
||||||
- [How to connect to Database](https://github.com/sdogruyol/kemal-pg-sample)
|
- [How to connect to Database](https://github.com/sdogruyol/kemal-pg-sample)
|
||||||
|
|
|
@ -3,8 +3,6 @@ layout: doc
|
||||||
title: "Getting Started"
|
title: "Getting Started"
|
||||||
---
|
---
|
||||||
|
|
||||||
# Kemal Tutorial
|
|
||||||
|
|
||||||
## 1. Install Crystal
|
## 1. Install Crystal
|
||||||
|
|
||||||
```
|
```
|
||||||
|
|
|
@ -1,10 +1,8 @@
|
||||||
---
|
---
|
||||||
layout: doc
|
layout: doc
|
||||||
title: HTTP Requests and Responses
|
title: HTTP Request / Response Lifecycle
|
||||||
---
|
---
|
||||||
|
|
||||||
# HTTP Request / Response Lifecycle
|
|
||||||
|
|
||||||
Accessing the HTTP request/response environment (query params, body, content_type, headers, status_code) is super easy. You can use the environment returned from the block:
|
Accessing the HTTP request/response environment (query params, body, content_type, headers, status_code) is super easy. You can use the environment returned from the block:
|
||||||
|
|
||||||
```ruby
|
```ruby
|
||||||
|
|
|
@ -3,8 +3,6 @@ layout: doc
|
||||||
title: Serving JSON API
|
title: Serving JSON API
|
||||||
---
|
---
|
||||||
|
|
||||||
# Serving JSON API
|
|
||||||
|
|
||||||
You need to return a ```JSON``` object or need to convert the existing object via `to_json`.
|
You need to return a ```JSON``` object or need to convert the existing object via `to_json`.
|
||||||
|
|
||||||
```ruby
|
```ruby
|
||||||
|
|
|
@ -3,9 +3,29 @@ layout: doc
|
||||||
title: Middlewares
|
title: Middlewares
|
||||||
---
|
---
|
||||||
|
|
||||||
# Middlewares
|
## Built-in Middlewares
|
||||||
|
|
||||||
You can create your own middlewares by inheriting from ```HTTP::Handler```
|
Kemal has built-in middlewares for common use cases.
|
||||||
|
|
||||||
|
### HTTP Basic Authorization
|
||||||
|
|
||||||
|
This middleware lets you add HTTP Basic Authorization to your Kemal application.
|
||||||
|
You can easily use this middleware with `basic_auth` macro like below.
|
||||||
|
|
||||||
|
```ruby
|
||||||
|
require "kemal"
|
||||||
|
|
||||||
|
basic_auth "username", "password"
|
||||||
|
|
||||||
|
get "/" do
|
||||||
|
"This won't render without correct username and password."
|
||||||
|
end
|
||||||
|
|
||||||
|
```
|
||||||
|
|
||||||
|
## Custom middlewares
|
||||||
|
|
||||||
|
You can create your own middleware by inheriting from ```HTTP::Handler```
|
||||||
|
|
||||||
```ruby
|
```ruby
|
||||||
class CustomHandler < HTTP::Handler
|
class CustomHandler < HTTP::Handler
|
||||||
|
|
|
@ -3,8 +3,6 @@ layout: doc
|
||||||
title: Restful Web Services
|
title: Restful Web Services
|
||||||
---
|
---
|
||||||
|
|
||||||
# Restful Web Services
|
|
||||||
|
|
||||||
You can handle HTTP methods as easy as writing method names and the route with a code block. Kemal will handle all the hard work.
|
You can handle HTTP methods as easy as writing method names and the route with a code block. Kemal will handle all the hard work.
|
||||||
|
|
||||||
```
|
```
|
||||||
|
|
|
@ -1,20 +1,36 @@
|
||||||
---
|
---
|
||||||
layout: doc
|
layout: doc
|
||||||
title: Serving Static Files
|
title: Static Files
|
||||||
---
|
---
|
||||||
|
|
||||||
## Static Files
|
# Statics
|
||||||
|
|
||||||
Kemal has built-in support for serving your static files. You need to put your static files under your ```/public``` directory.
|
Add your files to `public` directory and Kemal will serve these files immediately.
|
||||||
|
|
||||||
E.g: A static file like ```/public/index.html``` will be served with the matching route ```/index.html```.
|
```
|
||||||
|
app/
|
||||||
|
src/
|
||||||
|
your_app.cr
|
||||||
|
public/
|
||||||
|
js/
|
||||||
|
jquery.js
|
||||||
|
your_app.js
|
||||||
|
css/
|
||||||
|
your_app.css
|
||||||
|
index.html
|
||||||
|
```
|
||||||
|
|
||||||
## Production / Development Mode
|
Open index.html and add
|
||||||
|
|
||||||
By default Kemal starts in ```development```mode and logs to STDOUT.
|
```html
|
||||||
|
<html>
|
||||||
You can use ```production``` mode to redirect the output to a file. By default Kemal logs the output to ```kemal.log```.
|
<head>
|
||||||
|
<script src="/js/jquery.js"></script>
|
||||||
You can start Kemal in production mode by:
|
<script src="/js/your_app.js"></script>
|
||||||
|
<link rel="stylesheet" href="/css/your_app.css"/>
|
||||||
```./your_app -e production```
|
</head>
|
||||||
|
<body>
|
||||||
|
...
|
||||||
|
</body>
|
||||||
|
</html>
|
||||||
|
```
|
||||||
|
|
|
@ -1,36 +0,0 @@
|
||||||
---
|
|
||||||
layout: doc
|
|
||||||
title: Statics
|
|
||||||
---
|
|
||||||
|
|
||||||
# Statics
|
|
||||||
|
|
||||||
Add your files to `public` directory and Kemal will serve these files immediately.
|
|
||||||
|
|
||||||
```
|
|
||||||
app/
|
|
||||||
src/
|
|
||||||
your_app.cr
|
|
||||||
public/
|
|
||||||
js/
|
|
||||||
jquery.js
|
|
||||||
your_app.js
|
|
||||||
css/
|
|
||||||
your_app.css
|
|
||||||
index.html
|
|
||||||
```
|
|
||||||
|
|
||||||
Open index.html and add
|
|
||||||
|
|
||||||
```html
|
|
||||||
<html>
|
|
||||||
<head>
|
|
||||||
<script src="/js/jquery.js"></script>
|
|
||||||
<script src="/js/your_app.js"></script>
|
|
||||||
<link rel="stylesheet" href="/css/your_app.css"/>
|
|
||||||
</head>
|
|
||||||
<body>
|
|
||||||
...
|
|
||||||
</body>
|
|
||||||
</html>
|
|
||||||
```
|
|
|
@ -3,8 +3,6 @@ layout: doc
|
||||||
title: Using Dynamic Views
|
title: Using Dynamic Views
|
||||||
---
|
---
|
||||||
|
|
||||||
# Views
|
|
||||||
|
|
||||||
You can use ERB-like built-in **ECR** views to render files.
|
You can use ERB-like built-in **ECR** views to render files.
|
||||||
|
|
||||||
```ruby
|
```ruby
|
||||||
|
|
|
@ -3,8 +3,6 @@ layout: doc
|
||||||
title: Websockets
|
title: Websockets
|
||||||
---
|
---
|
||||||
|
|
||||||
# Using Websockets
|
|
||||||
|
|
||||||
Using Websockets is super easy! By nature Websockets are a bit different than standard Http Request / Response lifecycle.
|
Using Websockets is super easy! By nature Websockets are a bit different than standard Http Request / Response lifecycle.
|
||||||
|
|
||||||
You can easily create a websocket handler which matches the route of `ws://host:port/route. You can create more than 1 websocket handler
|
You can easily create a websocket handler which matches the route of `ws://host:port/route. You can create more than 1 websocket handler
|
||||||
|
|
|
@ -11,16 +11,4 @@
|
||||||
</li>
|
</li>
|
||||||
{% endfor %}
|
{% endfor %}
|
||||||
</ul>
|
</ul>
|
||||||
|
|
||||||
<h1 class="doc-heading">Examples</h1>
|
|
||||||
|
|
||||||
<ul class="doc-list">
|
|
||||||
{% for post in site.examples %}
|
|
||||||
<li>
|
|
||||||
<h2>
|
|
||||||
<a class="doc-link" href="{{ post.url | prepend: site.baseurl }}">{{ post.title }}</a>
|
|
||||||
</h2>
|
|
||||||
</li>
|
|
||||||
{% endfor %}
|
|
||||||
</ul>
|
|
||||||
</div>
|
</div>
|
||||||
|
|
|
@ -8,7 +8,7 @@ layout: home
|
||||||
Kemal
|
Kemal
|
||||||
</h1>
|
</h1>
|
||||||
<h2>
|
<h2>
|
||||||
Kemal is a fast, easy to use micro web framework written in Crystal language.
|
Lightning Fast, Super Simple micro web framework written in Crystal language.
|
||||||
<br />
|
<br />
|
||||||
It's inspired from Sinatra.
|
It's inspired from Sinatra.
|
||||||
</h2>
|
</h2>
|
||||||
|
@ -42,7 +42,7 @@ end
|
||||||
<li>Support all REST verbs</li>
|
<li>Support all REST verbs</li>
|
||||||
<li>Websocket support</li>
|
<li>Websocket support</li>
|
||||||
<li>Request/Response context, easy parameter handling</li>
|
<li>Request/Response context, easy parameter handling</li>
|
||||||
<li>Custom and built-in middlewares</li>
|
<li>Built-in and easily extensible middlewares</li>
|
||||||
<li>Built-in JSON support</li>
|
<li>Built-in JSON support</li>
|
||||||
<li>Built-in static file serving</li>
|
<li>Built-in static file serving</li>
|
||||||
<li>Built-in view templating via ecr</li>
|
<li>Built-in view templating via ecr</li>
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue