
Security News
ECMAScript 2025 Finalized with Iterator Helpers, Set Methods, RegExp.escape, and More
ECMAScript 2025 introduces Iterator Helpers, Set methods, JSON modules, and more in its latest spec update approved by Ecma in June 2025.
Decided to share this thanks to some research I did on APIs. Most of them have a base URL, then API endpoint, API username, a API password and transmits data in form of JSON. Then there are requests and responses. This could be a simple solution to access and work with a big or small APIs.
Please give Ruby's Net::HTTP Library a go. That is the backbone behind this. Net::HTTP simple, does the job, it is fast and build on top Ruby's IO so straight to the point.
gem 'any_api'
And then execute:
$ bundle
Or install it yourself as:
$ gem install any_api
If you are going to use this with Rails. Add bellow code your application.rb file, or the application_controller.rb file or as an initialiser file. It would work fine with any other Ruby project.
AnyApi.configure do |config|
#please dont put a "/" at the end of the api_base_url
config.api_base_url = "https://iamfree.com/api/v1"
#Dont need bellow authentication information if the API does not need username and password
config.username = "me@example.com"
config.password = "my-sectret-password"
end
Then you can call any API with
response = AnyApi::Request.new("Get", 'products.json' )
The first parameter is the HTTP method. Secondly it is the url endpoint.
If you want to do Post or Update calls please send parameters with your request
my_params = {"year"=>"2014", "country"=>"Australia", "first_name"=>"True", "last_name"=>"Colours"}
response = AnyApi::Request.new( "Post", 'users/new', my_params)
To parse the response
response.parser_response
If you want assert that the API call is a success before save your information database you could use the is_ok? method
if response.is_ok?
good_json = response.parser_response
......
else
bad_json_error_message = response.parser_response
.....
end
Thanks
git checkout -b my-new-feature
)git commit -am 'Add some feature'
)git push origin my-new-feature
)FAQs
Unknown package
We found that any_api demonstrated a not healthy version release cadence and project activity because the last version was released 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
ECMAScript 2025 introduces Iterator Helpers, Set methods, JSON modules, and more in its latest spec update approved by Ecma in June 2025.
Security News
A new Node.js homepage button linking to paid support for EOL versions has sparked a heated discussion among contributors and the wider community.
Research
North Korean threat actors linked to the Contagious Interview campaign return with 35 new malicious npm packages using a stealthy multi-stage malware loader.