Skip to content

Commit c73b290

Browse files
committed
Examples updated
1 parent 7aec87a commit c73b290

File tree

17 files changed

+108
-69
lines changed

17 files changed

+108
-69
lines changed
File renamed without changes.

examples/README.md

Lines changed: 34 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2,16 +2,47 @@
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/raw/master/examples/hello_world.rb)
66

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

99

10-
2. ###[Params](https://github.com/maxbarsukov/yaframework/tree/master/examples/params)
10+
2. [**Params**](https://github.com/maxbarsukov/yaframework/raw/master/examples/params.rb)
1111

1212
Shows how the application parameters can be used
1313

1414

15-
3. ###[Halts and Redirects](https://github.com/maxbarsukov/yaframework/tree/master/examples/halts-and-redirects)
15+
3. [**Halts and Redirects**](https://github.com/maxbarsukov/yaframework/raw/master/examples/halts_and_redirects.rb)
1616

1717
Shows how to use halts and redirects
18+
19+
20+
4. [**Headers**](https://github.com/maxbarsukov/yaframework/raw/master/examples/headers.rb)
21+
22+
How to add and view headers.
23+
24+
25+
5. [**Error handling**](https://github.com/maxbarsukov/yaframework/raw/master/examples/error_handling.rb)
26+
27+
How to handle errors
28+
29+
30+
6. [**Content Types**](https://github.com/maxbarsukov/yaframework/raw/master/examples/content_types.rb)
31+
32+
Using json, html, or plain text
33+
34+
35+
7. [**Cookies**](https://github.com/maxbarsukov/yaframework/raw/master/examples/cookies.rb)
36+
37+
Adding and deleting cookies
38+
39+
40+
## Installation
41+
42+
Clone this repo and go to this folder.
43+
Then, run `bundle install` to install this gem.
44+
45+
## Run
46+
47+
Run with `ruby hello-world.rb` or any other file and view at http://localhost:4567
48+

examples/content_types.rb

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
# frozen_string_literal: true
2+
3+
require "yaframework"
4+
app = Yaframework::Application
5+
6+
app.get "/" do
7+
response.redirect "/html"
8+
end
9+
10+
app.get "/html" do
11+
response.html "This is <b>HTML</b>, where you cat use some <small>tags</small>.
12+
<br/>JSON <a href=\"/json\">here</a>,
13+
<br/>Plain text <a href=\"/text\">here</a>"
14+
end
15+
16+
app.get "/text" do
17+
response.text "Just plain text.<br/>Boring, even tags don't work..."
18+
end
19+
20+
app.get "/json" do
21+
response.json "{ \"The awesomeness of this framework\": \"100/100\" }"
22+
end
23+
24+
app.listen(4567)

examples/cookies.rb

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
# frozen_string_literal: true
2+
3+
require "yaframework"
4+
app = Yaframework::Application
5+
6+
app.get "/" do
7+
response.set_cookie("foo", "bar")
8+
"Your cookies, sir: #{response["Set-Cookie"]}.<br/>Go <a href=\"/delete\">here</a> to delete them"
9+
end
10+
11+
app.get "/delete" do
12+
response.delete_cookie("foo")
13+
"Your cookies, sir: #{response["Set-Cookie"]}"
14+
end
15+
16+
app.listen(4567)

examples/error_handling.rb

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
# frozen_string_literal: true
2+
3+
require "yaframework"
4+
app = Yaframework::Application
5+
6+
app.get "/" do
7+
"This is the root, go somewhere else..<br/>Maybe <a href=\"/asdfg\">here</a>, idk"
8+
end
9+
10+
app.handle 404 do
11+
"Hey, I just handled a 404 error!<br/>The dude from the previous page deceived you!"
12+
end
13+
14+
app.handle 500 do
15+
"Error 500, this shouldn't have happened..."
16+
end
17+
18+
app.listen(4567)

examples/halts-and-redirects/README.md

Lines changed: 0 additions & 12 deletions
This file was deleted.

examples/halts-and-redirects/config.ru

Lines changed: 0 additions & 6 deletions
This file was deleted.

examples/halts-and-redirects/app.rb renamed to examples/halts_and_redirects.rb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@
88
end
99

1010
app.get "/hello" do
11-
"Hello world!"
11+
"Hi, you were redirected here from the root page. You can go <a href=\"/error\"></a> to get a 401 error"
1212
end
1313

1414
app.get "/error" do

examples/headers.rb

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
# frozen_string_literal: true
2+
3+
require "yaframework"
4+
app = Yaframework::Application
5+
6+
app.get "/" do
7+
request[:username] = "IVAN!"
8+
"Now 'request[:username]': #{request[:username]} contains in 'request.params': #{request.params}"
9+
end
10+
11+
app.listen(4567)

examples/hello-world/Gemfile

Lines changed: 0 additions & 5 deletions
This file was deleted.

0 commit comments

Comments
 (0)