udp_rest 0.9.0 → 0.9.2

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 5c547a1a4aeafe5240118f42f1d060b861bba377
4
- data.tar.gz: 1f67cc942b89d5d8da7b12066d019b96eaa54cf1
3
+ metadata.gz: 904e404e65a334a0320065c54d102768c7a3e871
4
+ data.tar.gz: '07768180b9432171234523f242bbf6e755276a67'
5
5
  SHA512:
6
- metadata.gz: 637dbc37f4e52a049b500f09aa60dcf167f27434fcfc9c2ea5c5fe8b442fc128e1d8cccf6b35c14ea42f3596c135cd1df3b03a1a5dea8f34f663dc8d56ebac33
7
- data.tar.gz: e592fdfff3610df362d4a558d15bda20dde2b61302f4bafdb1ddbaebca62053291e71f101e349308ea8eb849725ae21e3cb6050ba5bcaaaa44fdb0b5d780ac0e
6
+ metadata.gz: 201b29a6818926a2a357902942ababb665ab2125740af71ef74cc90c9c317159f6fe1ae68a4111134f520881a32534144fab2941ccc89867ea9c725b54f190bc
7
+ data.tar.gz: 05ad627e079d76e0b505faab919aea4c33ae0fb16b92bae7c901e8612045950c63aa4e53569d8d1a114107f632b2157f65bd972dc1b9f3b41b4025d9addc5823
@@ -1,7 +1,7 @@
1
1
  PATH
2
2
  remote: .
3
3
  specs:
4
- udp_rest (0.9.0)
4
+ udp_rest (0.9.2)
5
5
  colorize
6
6
  trollop
7
7
 
@@ -21,4 +21,4 @@ DEPENDENCIES
21
21
  udp_rest!
22
22
 
23
23
  BUNDLED WITH
24
- 1.12.5
24
+ 1.13.6
Binary file
@@ -125,6 +125,7 @@ module UDPRest
125
125
  req = UHTTPRequest.new
126
126
  req.req_method = req_method
127
127
  req.path = uri.path
128
+ req.query = uri.query
128
129
 
129
130
  packet = client.send_text(req.to_s)
130
131
  UHTTPResponse.parse(packet.text)
@@ -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} #{path} #{protocol}\n"
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
 
@@ -1,3 +1,3 @@
1
1
  module UDPRest
2
- VERSION = "0.9.0"
2
+ VERSION = "0.9.2"
3
3
  end
data/readme.md CHANGED
@@ -1,35 +1,41 @@
1
1
  # REST over UDP
2
2
 
3
- - Most REST requets are very small
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
- ## Try it out
5
+ The request and response size is limited 512 bytes, so this model is only appropriate for certain apis.
12
6
 
13
- There is a udp rest server running on uhttp.reednj.com. You can make requests to it by installing the gem.
7
+ ## Try it out
14
8
 
15
- gem install udp_rest
16
- udp-rest uhttp.reednj.com
9
+ There is a udp rest server running on uhttp.reednj.com, port 7890.
17
10
 
18
- <SCREEN SHOT OF CONSOLE>
11
+ gem install udp_rest
12
+ udp-rest uhttp.reednj.com:7890
19
13
 
20
- ## Server
14
+ ![terminal](docs/term.png)
21
15
 
22
- Use this gem to create sinatra style servers to respond to requests.
16
+ Some other urls to try are:
23
17
 
24
- <CODE>
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
- ## Benchmarks
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
- - do some testing of the latency here, see if it really is faster. Pick a few different servers
31
+ Use the `UDPRest::Server` class to create simple sinatra-style servers
31
32
 
32
- ## Other Points
33
+ UDPRest::Server.new(:port => 7890) do |s|
34
+ s.get '/'
35
+ 'hello, world!'
36
+ end
33
37
 
34
- - encoding is always UTF-8
35
- - the max request and response size is 512 bytes
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.0
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: 2016-12-09 00:00:00.000000000 Z
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