NetHttp2 开源项目教程
net-http2NetHttp2 is an HTTP/2 client for Ruby.项目地址:https://gitcode.com/gh_mirrors/ne/net-http2
1. 项目的目录结构及介绍
NetHttp2 项目的目录结构如下:
net-http2/
├── bin/
├── lib/
├── spec/
├── .gitignore
├── .rspec
├── .tool-versions
├── Gemfile
├── LICENSE.md
├── README.md
├── Rakefile
└── net-http2.gemspec
目录介绍
- bin/: 包含可执行文件。
- lib/: 包含项目的核心代码。
- spec/: 包含测试文件。
- .gitignore: Git 忽略文件配置。
- .rspec: RSpec 配置文件。
- .tool-versions: 用于指定项目使用的工具版本。
- Gemfile: 依赖管理文件。
- LICENSE.md: 项目许可证文件。
- README.md: 项目说明文档。
- Rakefile: Rake 任务配置文件。
- net-http2.gemspec: 项目 gem 的规范文件。
2. 项目的启动文件介绍
NetHttp2 项目的启动文件位于 lib/
目录下。主要的启动文件是 net-http2.rb
,它包含了项目的核心逻辑和接口。
require 'net-http2'
# 创建客户端
client = NetHttp2::Client.new("http://nghttp2.org")
# 发送请求
response = client.call(:get, '/')
# 读取响应
response.ok # => true
response.status # => '200'
response.headers # => [":status"=>"200"]
response.body # => "A body"
# 关闭连接
client.close
3. 项目的配置文件介绍
NetHttp2 项目的配置文件主要是 net-http2.gemspec
和 Gemfile
。
net-http2.gemspec
net-http2.gemspec
文件定义了 gem 的规范,包括名称、版本、作者、依赖等信息。
Gem::Specification.new do |spec|
spec.name = "net-http2"
spec.version = "0.17.0"
spec.authors = ["Luca Ostinelli"]
spec.email = ["l.ostinelli@gmail.com"]
spec.summary = "NetHttp2 is an HTTP/2 client for Ruby"
spec.description = "NetHttp2 is an HTTP/2 client for Ruby"
spec.homepage = "https://github.com/ostinelli/net-http2"
spec.license = "MIT"
spec.files = `git ls-files -z`.split("\x0")
spec.executables = spec.files.grep(%r{^bin/}) { |f| File.basename(f) }
spec.test_files = spec.files.grep(%r{^(test|spec|features)/})
spec.require_paths = ["lib"]
spec.add_development_dependency "bundler", "~> 1.7"
spec.add_development_dependency "rake", "~> 10.0"
spec.add_development_dependency "rspec", "~> 3.1"
spec.add_development_dependency "simplecov", "~> 0.9"
spec.add_development_dependency "coveralls", "~> 0.8"
spec.add_development_dependency "webmock", "~> 1.20"
spec.add_development_dependency "rubocop", "~> 0.28"
spec.add_development_dependency "pry-byebug", "~> 3.1"
spec.add_development_dependency "yard", "~> 0.8"
spec.add_development_dependency "redcarpet", "~> 3.2"
spec.add_runtime_dependency "http-2", "~> 0.8"
end
Gemfile
Gemfile
文件定义了项目的依赖关系。
source 'https://rubygems.org'
gem 'net-http2'
以上是 NetHttp2
net-http2NetHttp2 is an HTTP/2 client for Ruby.项目地址:https://gitcode.com/gh_mirrors/ne/net-http2