toycol 0.3.1 → 1.0.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (5) hide show
  1. checksums.yaml +4 -4
  2. data/CHANGELOG.md +15 -2
  3. data/README.md +169 -3
  4. data/lib/toycol/version.rb +1 -1
  5. metadata +1 -1
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 94c69c1ed2726e69431304ff3c4fb727581b7893160d5dbe085731f4d85dfce2
4
- data.tar.gz: 94fc2c13fbd5149a47669a521dfa40377e1edf890a92b33468bf534c6d34ed45
3
+ metadata.gz: b1b8a58a4fd3f08fc0efe5c808ed00f1fdd78e66b8b0c5467f4deb314f504fde
4
+ data.tar.gz: 86c53cfa48a4331cde4e5888b92a28645bb88b81695b8996b0ef301958364575
5
5
  SHA512:
6
- metadata.gz: c5c3d01ea2c3b41491e3d365b781d92677ef027ce9fefa1d45b3ab360e947416035c39d5c9d32dd29ae01c309dfa27338097e5a63dfcd248aa9647b45784bb28
7
- data.tar.gz: d09afa0497d2b40fcc0b404a19ceee343b9f132a434cbf80feef1cac3bbef060397bccc15503beb507be6e0b03d33b6d5f5cdbe96c5499a093b3a8a27dbd8f24
6
+ metadata.gz: 6f98b7f6753378032835b787f2f46c1679d6d5df5b88188a1e8f4350ae486146cad37ea1b8f67ec2af0d6f91e8ed24015154a2048f5891d4fb89f662ae912aee
7
+ data.tar.gz: '054893839fdaea8dfb45701e1f2a0cca55c19287e03d18a9266f2547502bb4c18d4fe97b822960aeef208044660e30262bc89945d269a047f3c6398c954c99e8'
data/CHANGELOG.md CHANGED
@@ -1,5 +1,18 @@
1
+ # Changelog
2
+
3
+ All notable changes to this project will be documented in this file. For info on how to format all future additions to this file please reference [Keep A Changelog](https://keepachangelog.com/en/1.0.0/).
4
+
1
5
  ## [Unreleased]
2
6
 
3
- ## [0.0.1] - 2021-07-12
7
+ ## [1.0.0] - 2021-07-27
8
+
9
+ The first major release of Toycol.The main features are:
4
10
 
5
- - Initial release
11
+ - [Added] Toycol::Protocol - For defining orignal application protocol
12
+ - [Added] Toycol::Proxy - For accepting requests and pass them to the background server
13
+ - [Added] Toycol::Command - For user friendly CLI
14
+ - `$ toycol server` - For starting proxy & background server
15
+ - `$ toycol client` - For sending request message to server
16
+ - `$ toycol generate` - For generating skeletons of Protocolfile & application
17
+ - [Added] Toycol::Server - As a built-in background server
18
+ - [Added] Rack::Handler::Toycol - For running Rack compartible application & switching background server
data/README.md CHANGED
@@ -1,13 +1,122 @@
1
1
  # Toycol
2
2
 
3
- Toy Application Protocol framework
3
+ Toycol is a small framework for defining toy application protocols.
4
+
5
+ You can define your own application protocol only by writing a parser in Toycol DSL for request messages.
6
+
7
+ Since the server and client programs to run the protocol are built-in from the beginning, you only need to prepare the following two items to run your custom protocol.
8
+ - A configuration file named like `Protocolfile`, `Protocolfile.protocol_name` and so on
9
+ - A Rack compartible application(e.g. `config.ru`)
10
+
11
+ In the real world, there is (yet) no full-fledged web server or browser in the world that runs on the custom protocol you devised.
12
+ Therefore, the protocol defined by this framework is in fact a "toy".
13
+ However, by using this framework, you will be able to experience and learn how the connection between the application layer and the transport layer is, and how the application protocol works on the transport layer.
14
+
15
+ ## Example(on original "Duck" protocol)
16
+
17
+ In this protocol:
18
+ - Client would send message like: `"quack, quack /posts<3user_id=1"`
19
+ - Server would interpret client message: `"GET /posts?user_id=1"`
20
+
21
+ You write your definition in Protocolfile
22
+
23
+ ```ruby
24
+ # Protocolfile.duck (protocol file)
25
+
26
+ Protocol.define(:duck) do
27
+ # [OPTIONAL] You can add your original request methods
28
+ add_request_methods "OTHER"
29
+
30
+ # [OPTIONAL] You can define your custom status codes
31
+ custom_status_codes(
32
+ 600 => "I'm afraid you are not a duck..."
33
+ )
34
+
35
+ # [REQUIRED] Define how you parse request path from request message
36
+ request.path do |message|
37
+ %r{(?<path>\/\w*)}.match(message)[:path]
38
+ end
39
+
40
+ # [REQUIRED] Define how you parse query from request message
41
+ request.query do |message|
42
+ %r{\<3(?<query>.+)}.match(message) { |m| m[:query] }
43
+ end
44
+
45
+ # [REQUIRED] Define how you parse query from request message
46
+ request.http_method do |message|
47
+ case message.scan(/quack/).size
48
+ when 2 then "GET"
49
+ else "OTHER"
50
+ end
51
+ end
52
+ end
53
+ ```
54
+
55
+ Don't forget, you need to prepare your application as well.
56
+
57
+ ```ruby
58
+ # config_duck.ru (Rack compartible application)
59
+
60
+ require "rack"
61
+ require "toycol"
62
+
63
+ # Specify which protocol to use
64
+ Toycol::Protocol.use(:duck)
65
+
66
+ class App
67
+ def call(env)
68
+ case env["REQUEST_METHOD"]
69
+ when "GET"
70
+ [
71
+ 200,
72
+ { "Content-Type" => "text/html" },
73
+ ["Quack, Quack! This app is running by Duck protocol."]
74
+ ]
75
+ when "OTHER"
76
+ [
77
+ 600,
78
+ { "Content-Type" => "text/html" },
79
+ ["Sorry, this application is only for ducks...\n"]
80
+ ]
81
+ end
82
+ end
83
+ end
84
+
85
+ run App.new
86
+ ```
87
+
88
+ Then you run server & client
89
+
90
+ ```
91
+ # In terminal for server
92
+
93
+ $ toycol server config_duck.ru
94
+ Toycol starts build-in server, listening on unix:///tmp/toycol.socket
95
+ Toycol is running on localhost:9292
96
+ => Use Ctrl-C to stop
97
+ ```
98
+
99
+ ```
100
+ # In other terminal for client
101
+
102
+ $ toycol client "quack, quack /posts<3user_id=1"
103
+ [Toycol] Sent request message: quack, quack /posts<3user_id=1
104
+ ---
105
+ [Toycol] Received response message:
106
+
107
+ HTTP/1.1 200 OK
108
+ Content-Type: text/html
109
+ Content-Length: 32
110
+
111
+ Quack, Quack! This app is running by Duck protocol.
112
+ ```
4
113
 
5
114
  ## Installation
6
115
 
7
116
  Add this line to your application's Gemfile:
8
117
 
9
118
  ```ruby
10
- gem 'toycol'
119
+ gem "toycol"
11
120
  ```
12
121
 
13
122
  And then execute:
@@ -20,7 +129,64 @@ Or install it yourself as:
20
129
 
21
130
  ## Usage
22
131
 
23
- WIP
132
+ Toycol provides useful commands to define & run your protocol.
133
+
134
+ #### `toycol generate` - To define your new protocol
135
+
136
+ You can use `toycol generate` command to generate skeletons of Protocolfile and application.
137
+
138
+ ```
139
+ $ toycol generate PROTOCOL_NAME
140
+ ```
141
+
142
+ When you run this command, skeletons of `Protocolfile.PROTOCOL_NAME` and `config_PROTOCOL_NAME.ru` will be generated.
143
+ If you only need one of them, you can specify the type by `-t` option.
144
+
145
+ ```
146
+ $ toycol generate PROTOCOL_NAME -t protocol
147
+ # or
148
+ $ toycol generate PROTOCOL_NAME -t app
149
+ ```
150
+
151
+ If `PROTOCOL_NAME` is not specified, Protocolfile and config.ru will simply be generated.
152
+
153
+ ```
154
+ $ toycol generate
155
+ ```
156
+
157
+ #### `toycol server` - To run server by your protocol
158
+
159
+ After you prepare Protocolfile & application, you need to start server to run the application by `toycol server` command.
160
+
161
+ ```
162
+ # Please specify application file name
163
+ $ toycol server config_`PROTOCOL_NAME`.ru
164
+ ```
165
+
166
+ Then the server will start.
167
+
168
+ Normally, `toycol server` command will start the server built into toycol.
169
+ However, if Puma is already installed in your environment, it will start Puma by default.
170
+
171
+ If you want to explicitly specify which server to use, you can use the -u option.
172
+
173
+ ```
174
+ $ toycol server config_`PROTOCOL_NAME`.ru -u puma
175
+ # or
176
+ $ toycol server config_`PROTOCOL_NAME`.ru -u buid_in
177
+ ```
178
+
179
+ If you would like to check other options, run the command `toycol server -h`.
180
+
181
+ #### `toycol client` - To send request message by your protocol
182
+
183
+ When you would like to send the request message to the server, use `toycol client`.
184
+
185
+ ```
186
+ $ toycol client "YOUR REQUEST MESSAGE"
187
+ ```
188
+
189
+ If you would like to check other options, run the command `toycol client -h`.
24
190
 
25
191
  ## Development
26
192
 
@@ -1,5 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module Toycol
4
- VERSION = "0.3.1"
4
+ VERSION = "1.0.0"
5
5
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: toycol
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.3.1
4
+ version: 1.0.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Misaki Shioi