Skip to content

Commit 60ecd8b

Browse files
committed
Some examples added
1 parent fb5d490 commit 60ecd8b

File tree

9 files changed

+88
-2
lines changed

9 files changed

+88
-2
lines changed

examples/README.md

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,9 +2,16 @@
22

33
Here are some examples of applications created with Yaframework:
44

5-
1. [**Hello World**](https://github.com/maxbarsukov/yaframework/tree/master/examples/hello-world)
5+
1. ###[Hello World](https://github.com/maxbarsukov/yaframework/tree/master/examples/hello-world)
66

77
A simple application that displays "Hello world" to you.
88

99

10-
2. Be soon...
10+
2. ###[Params](https://github.com/maxbarsukov/yaframework/tree/master/examples/params)
11+
12+
Shows how the application parameters can be used
13+
14+
15+
3. ###[Halts and Redirects](https://github.com/maxbarsukov/yaframework/tree/master/examples/halts-and-redirects)
16+
17+
Shows how to use halts and redirects
Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
# frozen_string_literal: true
2+
3+
source "https://rubygems.org"
4+
5+
gem "yaframework"
Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
# Params
2+
3+
Shows how to use halts and redirects
4+
5+
## Installation
6+
7+
Clone this repo and go to this folder.
8+
Then, run `bundle install` to install this gem.
9+
10+
## Run
11+
12+
Run with `ruby app.rb` or `rackup` and view at http://localhost:4567
Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
# frozen_string_literal: true
2+
3+
require "yaframework"
4+
app = Yaframework::Application
5+
6+
app.get "/" do
7+
response.redirect "/hello"
8+
end
9+
10+
app.get "/hello" do
11+
"Hello world!"
12+
end
13+
14+
app.get "/error" do
15+
response.status = 401
16+
halt response.finish
17+
end
18+
19+
app.listen(4567)
Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
# frozen_string_literal: true
2+
3+
require "yaframework"
4+
require "./app"
5+
6+
run app

examples/params/Gemfile

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
# frozen_string_literal: true
2+
3+
source "https://rubygems.org"
4+
5+
gem "yaframework"

examples/params/README.md

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
# Params
2+
3+
Shows how the application parameters can be used
4+
5+
## Installation
6+
7+
Clone this repo and go to this folder.
8+
Then, run `bundle install` to install this gem.
9+
10+
## Run
11+
12+
Run with `ruby app.rb` or `rackup` and view at http://localhost:4567

examples/params/app.rb

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
# frozen_string_literal: true
2+
3+
require "yaframework"
4+
app = Yaframework::Application
5+
6+
app.get "/:name" do
7+
"Hello #{request.params[:name]}!"
8+
end
9+
10+
app.get "/:name/foo/:bar" do
11+
"Hello #{request.params[:name]} from #{request.params[:bar]}!"
12+
end
13+
14+
app.listen(4567)

examples/params/config.ru

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
# frozen_string_literal: true
2+
3+
require "yaframework"
4+
require "./app"
5+
6+
run app

0 commit comments

Comments
 (0)