udp_rest 0.9.0 → 0.9.2
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/Gemfile.lock +2 -2
- data/docs/term.png +0 -0
- data/lib/udp_rest.rb +1 -0
- data/lib/udp_rest/uhttp.rb +28 -2
- data/lib/udp_rest/version.rb +1 -1
- data/readme.md +26 -20
- metadata +3 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 904e404e65a334a0320065c54d102768c7a3e871
|
4
|
+
data.tar.gz: '07768180b9432171234523f242bbf6e755276a67'
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 201b29a6818926a2a357902942ababb665ab2125740af71ef74cc90c9c317159f6fe1ae68a4111134f520881a32534144fab2941ccc89867ea9c725b54f190bc
|
7
|
+
data.tar.gz: 05ad627e079d76e0b505faab919aea4c33ae0fb16b92bae7c901e8612045950c63aa4e53569d8d1a114107f632b2157f65bd972dc1b9f3b41b4025d9addc5823
|
data/Gemfile.lock
CHANGED
data/docs/term.png
ADDED
Binary file
|
data/lib/udp_rest.rb
CHANGED
data/lib/udp_rest/uhttp.rb
CHANGED
@@ -1,4 +1,5 @@
|
|
1
1
|
require 'uri'
|
2
|
+
require 'cgi'
|
2
3
|
require 'socket'
|
3
4
|
|
4
5
|
module UDPRest
|
@@ -6,6 +7,7 @@ module UDPRest
|
|
6
7
|
class UDPRest::UHTTPRequest
|
7
8
|
attr_accessor :req_method
|
8
9
|
attr_accessor :path
|
10
|
+
attr_accessor :query
|
9
11
|
attr_accessor :protocol
|
10
12
|
|
11
13
|
def initialize
|
@@ -22,14 +24,38 @@ module UDPRest
|
|
22
24
|
raise 'invalid request' if data.length != 3
|
23
25
|
req = self.new
|
24
26
|
req.req_method = data[0]
|
25
|
-
req.path = data[1]
|
26
27
|
req.protocol = data[2]
|
28
|
+
|
29
|
+
path_data = data[1].split('?')
|
30
|
+
req.path = path_data[0]
|
31
|
+
req.query = path_data[1] || '' if path_data.length > 1
|
32
|
+
|
27
33
|
return req
|
28
34
|
end
|
29
35
|
|
30
36
|
def to_s
|
31
37
|
self.path = '/' if path.nil? || path.empty?
|
32
|
-
"#{req_method} #{
|
38
|
+
"#{req_method} #{path_and_query} #{protocol}\n"
|
39
|
+
end
|
40
|
+
|
41
|
+
def path_and_query
|
42
|
+
if query.nil? || query.strip == ''
|
43
|
+
path
|
44
|
+
else
|
45
|
+
path + '?' + query
|
46
|
+
end
|
47
|
+
end
|
48
|
+
|
49
|
+
def params
|
50
|
+
return {} if query.nil? || query.strip == ''
|
51
|
+
|
52
|
+
if @params.nil?
|
53
|
+
@params = {}
|
54
|
+
p = CGI.parse(self.query)
|
55
|
+
p.each {|k,v| @params[k] = v.first }
|
56
|
+
end
|
57
|
+
|
58
|
+
@params
|
33
59
|
end
|
34
60
|
end
|
35
61
|
|
data/lib/udp_rest/version.rb
CHANGED
data/readme.md
CHANGED
@@ -1,35 +1,41 @@
|
|
1
1
|
# REST over UDP
|
2
2
|
|
3
|
-
-
|
4
|
-
- it should be possible to implement a simple version of HTTP that can run over UDP in order to make REST requets
|
5
|
-
- we have implemented that
|
6
|
-
- the max packet size is 512 bytes
|
7
|
-
- This gem makes it easy to create servers and clients for udp-rest
|
8
|
-
- it also contains a curl-like command line app
|
9
|
-
- obviously this is not going to work from any browser, but it can be useful for simple command line apps.
|
3
|
+
REST is a useful pattern for client-server interaction, but for simple scenarios setting up an entire HTTP stack is overkill. This gem provides a classes to allow for REST over UDP using a http-like protocol, as well as a curl like app for making requests from the command line.
|
10
4
|
|
11
|
-
|
5
|
+
The request and response size is limited 512 bytes, so this model is only appropriate for certain apis.
|
12
6
|
|
13
|
-
|
7
|
+
## Try it out
|
14
8
|
|
15
|
-
|
16
|
-
udp-rest uhttp.reednj.com
|
9
|
+
There is a udp rest server running on uhttp.reednj.com, port 7890.
|
17
10
|
|
18
|
-
|
11
|
+
gem install udp_rest
|
12
|
+
udp-rest uhttp.reednj.com:7890
|
19
13
|
|
20
|
-
|
14
|
+
![terminal](docs/term.png)
|
21
15
|
|
22
|
-
|
16
|
+
Some other urls to try are:
|
23
17
|
|
24
|
-
|
18
|
+
- uhttp.reednj.com:7890/time/iso
|
19
|
+
- uhttp.reednj.com:7890/time/unix
|
20
|
+
- uhttp.reednj.com:7890/count
|
25
21
|
|
26
22
|
## Client
|
27
23
|
|
28
|
-
|
24
|
+
Use the `UDPRest::Client` class to make requests programmatically
|
25
|
+
|
26
|
+
UDPRest::Client.get('uhttp://uhttp.reednj.com:7890')
|
27
|
+
UDPRest::Client.post('uhttp://uhttp.reednj.com:7890')
|
28
|
+
|
29
|
+
## Server
|
29
30
|
|
30
|
-
|
31
|
+
Use the `UDPRest::Server` class to create simple sinatra-style servers
|
31
32
|
|
32
|
-
|
33
|
+
UDPRest::Server.new(:port => 7890) do |s|
|
34
|
+
s.get '/'
|
35
|
+
'hello, world!'
|
36
|
+
end
|
33
37
|
|
34
|
-
|
35
|
-
|
38
|
+
s.get '/time'
|
39
|
+
Time.now.to_s
|
40
|
+
end
|
41
|
+
end
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: udp_rest
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.9.
|
4
|
+
version: 0.9.2
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Nathan Reed
|
8
8
|
autorequire:
|
9
9
|
bindir: exe
|
10
10
|
cert_chain: []
|
11
|
-
date:
|
11
|
+
date: 2017-03-15 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: bundler
|
@@ -82,6 +82,7 @@ files:
|
|
82
82
|
- bin/console
|
83
83
|
- bin/setup
|
84
84
|
- demo/simple_server.rb
|
85
|
+
- docs/term.png
|
85
86
|
- exe/udp-rest
|
86
87
|
- lib/rest_client.rb
|
87
88
|
- lib/udp_rest.rb
|