rackget 0.1.0
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 +7 -0
- data/CODE_OF_CONDUCT.md +10 -0
- data/LICENSE.txt +21 -0
- data/README.md +42 -0
- data/Rakefile +8 -0
- data/exe/rackget +6 -0
- data/lib/rackget/cli.rb +88 -0
- data/lib/rackget/version.rb +5 -0
- data/lib/rackget.rb +40 -0
- metadata +66 -0
checksums.yaml
ADDED
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
---
|
|
2
|
+
SHA256:
|
|
3
|
+
metadata.gz: 3ae89253673e7bcadb64cdc7ede0a5faa537b10b7407e4f12fdbbbb379ffb964
|
|
4
|
+
data.tar.gz: 963dd878c61a8d3aa64f63f41335824f74a949ed7742e978db6fd1ee50c4de11
|
|
5
|
+
SHA512:
|
|
6
|
+
metadata.gz: 01b551f28c6c5798fc20788ca7b71d0fc56005d04435bffd722921eb58baa63020f80b1ea4952eeb256ad9716450d0cf00903865f72eba96dc3879c33959a2da
|
|
7
|
+
data.tar.gz: 00e8a792d558175cca91c267b2d88073888a563ce46c98c20fe141420469e3e8c25a636386d8c1712cc3f1b937750f38519fc00c40b41741e81549d2115e562c
|
data/CODE_OF_CONDUCT.md
ADDED
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
# Code of Conduct
|
|
2
|
+
|
|
3
|
+
"rackget" follows [The Ruby Community Conduct Guideline](https://www.ruby-lang.org/en/conduct) in all "collaborative space", which is defined as community communications channels (such as mailing lists, submitted patches, commit comments, etc.):
|
|
4
|
+
|
|
5
|
+
* Participants will be tolerant of opposing views.
|
|
6
|
+
* Participants must ensure that their language and actions are free of personal attacks and disparaging personal remarks.
|
|
7
|
+
* When interpreting the words and actions of others, participants should always assume good intentions.
|
|
8
|
+
* Behaviour which can be reasonably considered harassment will not be tolerated.
|
|
9
|
+
|
|
10
|
+
If you have any concerns about behaviour within this project, please contact us at ["john@hawthorn.email"](mailto:"john@hawthorn.email").
|
data/LICENSE.txt
ADDED
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
The MIT License (MIT)
|
|
2
|
+
|
|
3
|
+
Copyright (c) 2026 John Hawthorn
|
|
4
|
+
|
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
6
|
+
of this software and associated documentation files (the "Software"), to deal
|
|
7
|
+
in the Software without restriction, including without limitation the rights
|
|
8
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
9
|
+
copies of the Software, and to permit persons to whom the Software is
|
|
10
|
+
furnished to do so, subject to the following conditions:
|
|
11
|
+
|
|
12
|
+
The above copyright notice and this permission notice shall be included in
|
|
13
|
+
all copies or substantial portions of the Software.
|
|
14
|
+
|
|
15
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
16
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
17
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
18
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
19
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
20
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
|
|
21
|
+
THE SOFTWARE.
|
data/README.md
ADDED
|
@@ -0,0 +1,42 @@
|
|
|
1
|
+
# Rackget
|
|
2
|
+
|
|
3
|
+
Like curl for your Rack application
|
|
4
|
+
|
|
5
|
+
A command line utility to boot a Rack app and makes a request to it, without starting a server.
|
|
6
|
+
|
|
7
|
+
## Installation
|
|
8
|
+
|
|
9
|
+
```bash
|
|
10
|
+
gem install rackget
|
|
11
|
+
```
|
|
12
|
+
|
|
13
|
+
## Usage
|
|
14
|
+
|
|
15
|
+
```bash
|
|
16
|
+
# GET request (loads config.ru from current directory)
|
|
17
|
+
rackget /users
|
|
18
|
+
|
|
19
|
+
# Full URL (sets Host header)
|
|
20
|
+
rackget http://localhost/users?page=2
|
|
21
|
+
|
|
22
|
+
# Other HTTP methods
|
|
23
|
+
rackget -X POST -d 'name=foo' /users
|
|
24
|
+
rackget -X PUT -d '{"name":"bar"}' /users/1
|
|
25
|
+
rackget -X DELETE /users/1
|
|
26
|
+
|
|
27
|
+
# Custom headers
|
|
28
|
+
rackget -H 'Content-Type: application/json' -X POST -d '{"name":"foo"}' /users
|
|
29
|
+
|
|
30
|
+
# Show status and response headers
|
|
31
|
+
rackget -i /users
|
|
32
|
+
|
|
33
|
+
# Specify a rackup file
|
|
34
|
+
rackget -r myapp.ru /users
|
|
35
|
+
|
|
36
|
+
# Pipe request body from stdin
|
|
37
|
+
echo '{"name":"foo"}' | rackget -X POST /users
|
|
38
|
+
```
|
|
39
|
+
|
|
40
|
+
## License
|
|
41
|
+
|
|
42
|
+
MIT
|
data/Rakefile
ADDED
data/exe/rackget
ADDED
data/lib/rackget/cli.rb
ADDED
|
@@ -0,0 +1,88 @@
|
|
|
1
|
+
# frozen_string_literal: true
|
|
2
|
+
|
|
3
|
+
require "optparse"
|
|
4
|
+
require_relative "../rackget"
|
|
5
|
+
|
|
6
|
+
module Rackget
|
|
7
|
+
class CLI
|
|
8
|
+
def initialize(argv, stdout: $stdout, stdin: $stdin)
|
|
9
|
+
@stdout = stdout
|
|
10
|
+
@stdin = stdin
|
|
11
|
+
@options = {
|
|
12
|
+
rackup_file: "config.ru",
|
|
13
|
+
include_headers: false,
|
|
14
|
+
method: "GET",
|
|
15
|
+
data: nil,
|
|
16
|
+
headers: {}
|
|
17
|
+
}
|
|
18
|
+
|
|
19
|
+
@parser = OptionParser.new do |opts|
|
|
20
|
+
opts.banner = "Usage: rackget [options] PATH"
|
|
21
|
+
|
|
22
|
+
opts.on("-r", "--rackup FILE", "Rackup file (default: config.ru)") do |f|
|
|
23
|
+
@options[:rackup_file] = f
|
|
24
|
+
end
|
|
25
|
+
|
|
26
|
+
opts.on("-X", "--request METHOD", "HTTP method (default: GET)") do |m|
|
|
27
|
+
@options[:method] = m.upcase
|
|
28
|
+
end
|
|
29
|
+
|
|
30
|
+
opts.on("-d", "--data DATA", "Request body data") do |d|
|
|
31
|
+
@options[:data] = d
|
|
32
|
+
end
|
|
33
|
+
|
|
34
|
+
opts.on("-H", "--header HEADER", "Custom header (e.g. 'Content-Type: application/json')") do |h|
|
|
35
|
+
name, value = h.split(":", 2)
|
|
36
|
+
@options[:headers][name.strip] = value.strip
|
|
37
|
+
end
|
|
38
|
+
|
|
39
|
+
opts.on("-i", "--show-headers", "Include status and headers in output") do
|
|
40
|
+
@options[:include_headers] = true
|
|
41
|
+
end
|
|
42
|
+
end
|
|
43
|
+
|
|
44
|
+
@args = @parser.parse(argv)
|
|
45
|
+
end
|
|
46
|
+
|
|
47
|
+
def run
|
|
48
|
+
target = @args.first || "/"
|
|
49
|
+
path, query_string, host = parse_target(target)
|
|
50
|
+
@options[:headers]["Host"] ||= host if host
|
|
51
|
+
|
|
52
|
+
input = @options[:data]
|
|
53
|
+
input = @stdin.read if input.nil? && !@stdin.tty?
|
|
54
|
+
|
|
55
|
+
app = Rackget.load_app(@options[:rackup_file])
|
|
56
|
+
status, headers, body = Rackget.request(app, path,
|
|
57
|
+
method: @options[:method],
|
|
58
|
+
query_string: query_string,
|
|
59
|
+
input: input,
|
|
60
|
+
headers: @options[:headers]
|
|
61
|
+
)
|
|
62
|
+
|
|
63
|
+
if @options[:include_headers]
|
|
64
|
+
@stdout.puts "#{status} #{Rack::Utils::HTTP_STATUS_CODES[status]}"
|
|
65
|
+
headers.each { |k, v| @stdout.puts "#{k}: #{v}" }
|
|
66
|
+
@stdout.puts
|
|
67
|
+
end
|
|
68
|
+
|
|
69
|
+
body.each { |chunk| @stdout.write(chunk) }
|
|
70
|
+
body.close if body.respond_to?(:close)
|
|
71
|
+
|
|
72
|
+
status >= 400 ? 1 : 0
|
|
73
|
+
end
|
|
74
|
+
|
|
75
|
+
private
|
|
76
|
+
|
|
77
|
+
def parse_target(target)
|
|
78
|
+
uri = URI.parse(target)
|
|
79
|
+
path = uri.path
|
|
80
|
+
path = "/" if path.nil? || path.empty?
|
|
81
|
+
host = uri.host
|
|
82
|
+
host = "#{host}:#{uri.port}" if host && uri.port && uri.port != uri.default_port
|
|
83
|
+
[path, uri.query, host]
|
|
84
|
+
rescue URI::InvalidURIError
|
|
85
|
+
[target, nil, nil]
|
|
86
|
+
end
|
|
87
|
+
end
|
|
88
|
+
end
|
data/lib/rackget.rb
ADDED
|
@@ -0,0 +1,40 @@
|
|
|
1
|
+
# frozen_string_literal: true
|
|
2
|
+
|
|
3
|
+
require_relative "rackget/version"
|
|
4
|
+
|
|
5
|
+
require "rack"
|
|
6
|
+
require "rack/builder"
|
|
7
|
+
require "rack/mock_request"
|
|
8
|
+
require "uri"
|
|
9
|
+
|
|
10
|
+
module Rackget
|
|
11
|
+
class Error < StandardError; end
|
|
12
|
+
|
|
13
|
+
def self.load_app(rackup_file)
|
|
14
|
+
raise Error, "File not found: #{rackup_file}" unless File.exist?(rackup_file)
|
|
15
|
+
|
|
16
|
+
result = Rack::Builder.parse_file(rackup_file)
|
|
17
|
+
result.is_a?(Array) ? result.first : result
|
|
18
|
+
end
|
|
19
|
+
|
|
20
|
+
def self.request(app, path, method: "GET", query_string: nil, input: nil, headers: {})
|
|
21
|
+
url = path.dup
|
|
22
|
+
url = "#{url}?#{query_string}" if query_string && !query_string.empty?
|
|
23
|
+
|
|
24
|
+
opts = { method: method }
|
|
25
|
+
opts[:input] = input if input
|
|
26
|
+
|
|
27
|
+
headers.each do |name, value|
|
|
28
|
+
key = name.upcase.tr("-", "_")
|
|
29
|
+
key = "HTTP_#{key}" unless key == "CONTENT_TYPE" || key == "CONTENT_LENGTH"
|
|
30
|
+
opts[key] = value
|
|
31
|
+
end
|
|
32
|
+
|
|
33
|
+
env = Rack::MockRequest.env_for(url, opts)
|
|
34
|
+
app.call(env)
|
|
35
|
+
end
|
|
36
|
+
|
|
37
|
+
def self.get(app, path, query_string: nil)
|
|
38
|
+
request(app, path, method: "GET", query_string: query_string)
|
|
39
|
+
end
|
|
40
|
+
end
|
metadata
ADDED
|
@@ -0,0 +1,66 @@
|
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
|
2
|
+
name: rackget
|
|
3
|
+
version: !ruby/object:Gem::Version
|
|
4
|
+
version: 0.1.0
|
|
5
|
+
platform: ruby
|
|
6
|
+
authors:
|
|
7
|
+
- John Hawthorn
|
|
8
|
+
bindir: exe
|
|
9
|
+
cert_chain: []
|
|
10
|
+
date: 1980-01-02 00:00:00.000000000 Z
|
|
11
|
+
dependencies:
|
|
12
|
+
- !ruby/object:Gem::Dependency
|
|
13
|
+
name: rack
|
|
14
|
+
requirement: !ruby/object:Gem::Requirement
|
|
15
|
+
requirements:
|
|
16
|
+
- - ">="
|
|
17
|
+
- !ruby/object:Gem::Version
|
|
18
|
+
version: '2.0'
|
|
19
|
+
type: :runtime
|
|
20
|
+
prerelease: false
|
|
21
|
+
version_requirements: !ruby/object:Gem::Requirement
|
|
22
|
+
requirements:
|
|
23
|
+
- - ">="
|
|
24
|
+
- !ruby/object:Gem::Version
|
|
25
|
+
version: '2.0'
|
|
26
|
+
description: A command line utility that boots a Rack app from config.ru and makes
|
|
27
|
+
HTTP requests to it directly, without starting a server.
|
|
28
|
+
email:
|
|
29
|
+
- john@hawthorn.email
|
|
30
|
+
executables:
|
|
31
|
+
- rackget
|
|
32
|
+
extensions: []
|
|
33
|
+
extra_rdoc_files: []
|
|
34
|
+
files:
|
|
35
|
+
- CODE_OF_CONDUCT.md
|
|
36
|
+
- LICENSE.txt
|
|
37
|
+
- README.md
|
|
38
|
+
- Rakefile
|
|
39
|
+
- exe/rackget
|
|
40
|
+
- lib/rackget.rb
|
|
41
|
+
- lib/rackget/cli.rb
|
|
42
|
+
- lib/rackget/version.rb
|
|
43
|
+
homepage: https://github.com/jhawthorn/rackget
|
|
44
|
+
licenses:
|
|
45
|
+
- MIT
|
|
46
|
+
metadata:
|
|
47
|
+
homepage_uri: https://github.com/jhawthorn/rackget
|
|
48
|
+
source_code_uri: https://github.com/jhawthorn/rackget
|
|
49
|
+
rdoc_options: []
|
|
50
|
+
require_paths:
|
|
51
|
+
- lib
|
|
52
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
|
53
|
+
requirements:
|
|
54
|
+
- - ">="
|
|
55
|
+
- !ruby/object:Gem::Version
|
|
56
|
+
version: 3.2.0
|
|
57
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
|
58
|
+
requirements:
|
|
59
|
+
- - ">="
|
|
60
|
+
- !ruby/object:Gem::Version
|
|
61
|
+
version: '0'
|
|
62
|
+
requirements: []
|
|
63
|
+
rubygems_version: 4.0.3
|
|
64
|
+
specification_version: 4
|
|
65
|
+
summary: Load a Rack app and make requests to it from the command line
|
|
66
|
+
test_files: []
|