
Security News
vlt Launches "reproduce": A New Tool Challenging the Limits of Package Provenance
vlt's new "reproduce" tool verifies npm packages against their source code, outperforming traditional provenance adoption in the JavaScript ecosystem.
QuickRequest
is a lightweight Ruby gem designed to simplify making HTTP and HTTPS requests. It abstracts the complexities of crafting requests by providing a simple, fluent API using the Builder pattern. You can create GET, POST, PUT, and DELETE requests, add query parameters, set headers, and send request bodies easily.
To use the QuickRequest gem, add to your Gemfile
:
gem 'quick_request', '~> 1.0.0'
Or you can execute:
gem install quick_request
Obs: Ruby 3 is required
Here's a step-by-step guide on how to use the QuickRequest gem.
First, you need to create a Builder
object. This object allows you to configure your HTTP request.
request = QuickRequest::Builder.new(method: :get, url: 'https://api.example.com/data', use_ssl: true)
request = QuickRequest::Builder.new(url: 'http://localhost:3001')
method
: The HTTP method to use (:get
, :post
, :put
or :delete
). The default is :get
url
: The URL to send the request to.use_ssl
: Whether to use SSL for the request (default: false
).You can add query parameters to the request using the query_params
method. This method takes a hash of key-value pairs.
request.query_params({ key1: 'value1', key2: 'value2' })
This will append the query parameters to the URL.
For POST and PUT requests, you may want to send data in the request body
. You can do this with the body method.
request.body({ param1: 'value1', param2: 'value2' })
You can set custom headers for the request using the `headers method. This method takes a hash where the keys are header names, and the values are the corresponding header values.
request.headers({ 'Content-Type' => 'application/json', 'Authorization' => 'Bearer token' })
Once you've configured the request, you can send it using the send
method. This will return the response body.
response_body = request.send
Here's a full example of making a POST request with headers, query parameters, and a body:
require 'quick_request'
request = QuickRequest::Builder.new(method: :post, url: 'https://api.example.com/submit', use_ssl: true)
.query_params({ search: 'ruby' })
.headers({ 'Content-Type' => 'application/json', 'Authorization' => 'Bearer token' })
.body({ name: 'John', age: 30 })
response_body = request.send
puts response_body
# > "foo response from api..."
Currently, the gem raises a generic error if an unsupported HTTP method is used. More sophisticated error handling can be added by wrapping the send
method call in a begin-rescue
block.
So, if you want to collaborate with this project, your help is alwals welcome. You can open issues and create a PR here. So, go ahead!
FAQs
Unknown package
We found that quick_request demonstrated a healthy version release cadence and project activity because the last version was released less than a year ago. It has 1 open source maintainer collaborating on the project.
Did you know?
Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.
Security News
vlt's new "reproduce" tool verifies npm packages against their source code, outperforming traditional provenance adoption in the JavaScript ecosystem.
Research
Security News
Socket researchers uncovered a malicious PyPI package exploiting Deezer’s API to enable coordinated music piracy through API abuse and C2 server control.
Research
The Socket Research Team discovered a malicious npm package, '@ton-wallet/create', stealing cryptocurrency wallet keys from developers and users in the TON ecosystem.