public-apis | A collective list of free APIs | REST library
kandi X-RAY | public-apis Summary
Support
Quality
Security
License
Reuse
- Check file format
- Check the authentication option
- Extracts category line number and line number from contents
- Check if https is a valid HTTPS option
- Check CORS option
- Return an error message
- Check if lines are alphabetical order
- Check the title format
- Check description
- Check the validity of a single entry
- Check if links are working
- Return True if the response contains cloudflare protection
- Check if the link is working
- Get host from a link
- Return a random fake user agent
- Check if list of links are working
- Find links in a file
- Find links in text
- Check for duplicate links
public-apis Key Features
public-apis Examples and Code Snippets
POST /offer-service/api/v1/offers { "name: "offer name", "description: "offer description", "price: "5.00", "currency: "GBP", "duration: { "startDate: "2018-01-01", "endDate: "2018-01-31" } } Response HTTP Status 201 Created { id: "12c3009d-046d-411c-85eb-6e379e2f5d2a" }
POST /offer-service/api/v1/offers/{offer-id}/cancel Response HTTP Status 204 No Content
GET /offer-service/api/v1/offers` Response HTTP Status 200 offers: [ { id: "12c3009d-046d-411c-85eb-6e379e2f5d2a", name: "offer name", description: "offer description", price: "5.00", currency: "GBP", duration: { startDate: "2018-01-01", endDate: "2018-01-31" }, status: "ACTIVE|EXPIRED" }, { id: "cc3453d7-6d75-422c-87da-37ee9f65bd11", ... }, { id: "3f5f779c-b145-49fd-8a73-c8770fad072a", ... } ]
GET /offer-service/api/v1/offers/{offer-id}` Response HTTP Status 200 { id: "12c3009d-046d-411c-85eb-6e379e2f5d2a", name: "offer name", description: "offer description", price: "5.00", currency: "GBP", duration: { startDate: "2018-01-01", endDate: "2018-01-31" }, status: "ACTIVE|EXPIRED" } Or HTTP Status 404 Not Found
+------------------------------------+ +-------------------------+ | server2a | | server2b | | | | | | +--------------------------------+ | | +---------------------+ | | | ServiceSet | | | | ServiceSet | | | | | | | | | | | | +-----+ +-----+ | | | | +-------+ | | | | | | | | | | | | | | | | | | v | | v | | | | | v | | | | +------+ +-+--+-+ +--------+ | | | | +--+---+ +------+ | | | | | svc1 | | svc2 | | svc3 | | | | | | svc3 | | svc4 | | | | | +------+ +------+ | client +--+-+--+ | | +------+ +------+ | | | | ^ +--------+ | | | | | ^ | | | | | | | | | | | | | | +--------------+-----------------+ | | | +-----+---------------+ | | | | | | | | | +--------------+-----------------+ | | | +-----+---------------+ | | | Listener | | | | | | | Listener | | | | +--+---+ | | | | | +--+---+ | | | | | svc2 | | | | | | | svc3 | | | | | | cfg |<-+ | | +--+-+->| cfg | | | | | +------+ | | | | | +------+ | | | +---------------------+----------+ | | +---------------------+ | +-----------------------+------------+ +-------------------------+ | +-----------------------+----+ | test_client | | | | | | +---------------------+--+ | | | ServiceSet | | | | | | | | | | +--------+ | | | | | | svc2 +--+ | | | | | client | | | | | +---+----+ | | | | ^ | | | | | | | | +-------------+----------+ | | | | | +--+---+ | | | main | | | +------+ | +----------------------------+
const link = new RestLink({ endpoints: "/api", customFetch: (uri, options) => new Promise((resolve, reject) => { // Your own (asynchronous) request handler resolve(responseObject) }), });
import pThrottle from "p-throttle"; const link = new RestLink({ endpoints: "/api", customFetch: pThrottle((uri, config) => { return fetch(uri, config); }, 2, // Max. concurrent Requests 500 // Min. delay between calls ), });
Trending Discussions on public-apis
Trending Discussions on public-apis
QUESTION
Is there a simple online testing server (similar to Postman-echo.com) that I can use for JSON-RPC commands from Postman or for any other simple scripts that I might be writing?
On GitHub, I see lots of public APIs on GitHub (many that don't even need keys), but I unfortunately don't see any for JSON-RCP that I could use.
I also stumbled across this Guru JSON app, but it seems to only let me send JSON from the website, not from other apps like Postman.
ANSWER
Answered 2020-Jul-13 at 07:21I found Random.org and just tested it in Postman.
https://api.random.org/json-rpc/1/invoke
Works great for learning purposes!
QUESTION
I am a little bit confused about the meaning and the differences between these three terms.
- Interfaces
- APIs
- Public classes
I asked before if there is any difference between APIs and Public classes. Here is the question: Public methods vs public APIs
I got it, but now with the new concept Interface, I got confused again about the differences between Interface and API and Public class, so to make things clearer, let's see this sentence:
Information hiding allows developers to work on modules separately, without needing other developers to know the implementation details of the module they are working on. The module is instead used through its interface.
What is the meaning of interface here? Is it the same as public class?
ANSWER
Answered 2020-Jun-24 at 15:43A big reason these terms are confusing is because they are keywords in Java and they have meaning in a general, language-agnostic context. What the terms mean in the general context of programming is slightly different from what the specific keywords mean in Java.
In general, the term interface is synonymous with abstraction. When you read, "Program to an interface" it means program to an abstraction. In Java, the interface
keyword indicates a specific type of stateless abstraction, which is contrasted with abstract class
. In general, both of these are abstractions and thus both are programming interfaces.
In general, the term public indicates any part of code that is visible to and used by clients outside of the development team. In Java, the public
keyword indicates a specific access level between classes and members. Since clients may view and use protected
members as well, these may also be considered public in the general context of programming. Effective Java uses the term exported to combine public
and protected
members. Note that in Java 9+ modules can be used to control access, so even public
classes may not be exported and thus may not be public in the general sense.
The term API is not a Java keyword, so at least we have no language-specific ambiguity to contend with. It is typically used to mean public API, which is synonymous with exported API. It is the sum of everything that you (the developer) allow your clients to view and use. Occasionally, the term internal API is used to indicate the opposite: classes and members that you do not allow your clients to view or use.
QUESTION
I'm scraping a bunch of tables with httparty, then parsing the response with nokogiri. Everything works well, but then I get a phantom row at the top:
require 'nokogiri'
require 'httparty'
require 'byebug'
def scraper
url = "https://github.com/public-apis/public-apis"
parsed_page = Nokogiri::HTML(HTTParty.get(url))
# Get categories from the ul at the top
categories = parsed_page.xpath('/html/body/div[4]/div/main/div[2]/div/div/div/article/ul/li/a')
# Get all tables from the page
tables = parsed_page.xpath('/html/body/div[4]/div/main/div[2]/div/div/div/article/table')
rows = []
# Acting on one first for testing before making it dynamic
tables[0].search('tr').each do |tr|
cells = tr.search('td')
link = ''
values = []
row = {
'name' => '',
'description' => '',
'auth' => '',
'https' => '',
'cors' => '',
'category' => '',
'url' => ''
}
cells.css('a').each do |a|
link += a['href']
end
cells.each do |cell|
values << cell.text
end
values << categories[0].text
values << link
rows << row.keys.zip(values).to_h
end
puts rows
end
scraper
Result in console:
{"name"=>"Animals", "description"=>"", "auth"=>nil, "https"=>nil, "cors"=>nil, "category"=>nil, "url"=>nil}
{"name"=>"Cat Facts", "description"=>"Daily cat facts", "auth"=>"No", "https"=>"Yes",
...
Where is that first row coming from?
ANSWER
Answered 2020-Apr-24 at 21:44Your code could be much simpler and more resilient:
Meditate on this:
require 'nokogiri'
require 'httparty'
URL = 'https://github.com/public-apis/public-apis'
FIELDS = %w[name description auth https cors category url]
doc = Nokogiri::HTML(HTTParty.get(URL))
category = doc.at('article li a').text
rows = doc.at('article table').search('tr')[1..-1].map { |tr|
values = tr.search('td').map(&:text)
link = tr.at('a')['href']
Hash[
FIELDS.zip(values + [category, link])
]
}
Which results in:
puts rows
# >> {"name"=>"Cat Facts", "description"=>"Daily cat facts", "auth"=>"No", "https"=>"Yes", "cors"=>"No", "category"=>"Animals", "url"=>"https://alexwohlbruck.github.io/cat-facts/"}
# >> {"name"=>"Cats", "description"=>"Pictures of cats from Tumblr", "auth"=>"apiKey", "https"=>"Yes", "cors"=>"Unknown", "category"=>"Animals", "url"=>"https://docs.thecatapi.com/"}
# >> {"name"=>"Dogs", "description"=>"Based on the Stanford Dogs Dataset", "auth"=>"No", "https"=>"Yes", "cors"=>"Yes", "category"=>"Animals", "url"=>"https://dog.ceo/dog-api/"}
# >> {"name"=>"HTTPCat", "description"=>"Cat for every HTTP Status", "auth"=>"No", "https"=>"Yes", "cors"=>"Unknown", "category"=>"Animals", "url"=>"https://http.cat/"}
# >> {"name"=>"IUCN", "description"=>"IUCN Red List of Threatened Species", "auth"=>"apiKey", "https"=>"No", "cors"=>"Unknown", "category"=>"Animals", "url"=>"http://apiv3.iucnredlist.org/api/v3/docs"}
# >> {"name"=>"Movebank", "description"=>"Movement and Migration data of animals", "auth"=>"No", "https"=>"Yes", "cors"=>"Unknown", "category"=>"Animals", "url"=>"https://github.com/movebank/movebank-api-doc"}
# >> {"name"=>"Petfinder", "description"=>"Adoption", "auth"=>"OAuth", "https"=>"Yes", "cors"=>"Yes", "category"=>"Animals", "url"=>"https://www.petfinder.com/developers/v2/docs/"}
# >> {"name"=>"PlaceGOAT", "description"=>"Placeholder goat images", "auth"=>"No", "https"=>"Yes", "cors"=>"Unknown", "category"=>"Animals", "url"=>"https://placegoat.com/"}
# >> {"name"=>"RandomCat", "description"=>"Random pictures of cats", "auth"=>"No", "https"=>"Yes", "cors"=>"Yes", "category"=>"Animals", "url"=>"https://aws.random.cat/meow"}
# >> {"name"=>"RandomDog", "description"=>"Random pictures of dogs", "auth"=>"No", "https"=>"Yes", "cors"=>"Yes", "category"=>"Animals", "url"=>"https://random.dog/woof.json"}
# >> {"name"=>"RandomFox", "description"=>"Random pictures of foxes", "auth"=>"No", "https"=>"Yes", "cors"=>"No", "category"=>"Animals", "url"=>"https://randomfox.ca/floof/"}
# >> {"name"=>"RescueGroups", "description"=>"Adoption", "auth"=>"No", "https"=>"Yes", "cors"=>"Unknown", "category"=>"Animals", "url"=>"https://userguide.rescuegroups.org/display/APIDG/API+Developers+Guide+Home"}
# >> {"name"=>"Shibe.Online", "description"=>"Random pictures of Shibu Inu, cats or birds", "auth"=>"No", "https"=>"Yes", "cors"=>"Yes", "category"=>"Animals", "url"=>"http://shibe.online/"}
The issues with your code are:
Using
search('some selector')[0]
is the same asat('some selector')
only the second is cleaner resulting in less visual noise.There are other, more subtle, differences as far as what
search
returns in comparison toat
, which is covered in the documentation. I highly recommend reading and experimenting with their examples as knowing which to use when can save you headaches.Relying on absolute XPath selectors: An absolute selector is very fragile. Any change to the HTML will have a high-likelihood of breaking. Instead, find useful nodes to check that are unique, and let the parser find them.
Using a CSS selector
'article li a'
jumps through all the nodes until it finds the "article" node, looks inside it for the child "li" and following "a". You can do the same thing with XPath, but it's visually noisy. I'm a big fan of keeping my code as easy to read and comprehend as possible.Similarly,
at('article table')
finds the first table under the "article" node, thensearch('tr')
finds the embedded rows in only that table.Because you want to skip the table header
[1..-1]
slices the NodeSet and skips that first row.map
makes it easier to build a structure:
rows = doc.at('article table').search('tr')[1..-1].map { |tr|
assigns the fields to rows
in one pass through that loop of rows.
values
is assigned with the text of the NodeSet of every "td" node's text.
You can easily build a hash by using Hash's []
constructor and passing in an array of key/value pairs.
FIELDS.zip(values + [category, link])
is taking the values from the cells and adding a second array containing the category and link from the row.
My example code is basically the same template every time I scrape a page with a table. There'll be minor differences, but it's a loop over the table extracting the cells and converting them to a hash. It's even possible, on a cleanly written table, to automatically grab the keys of the hash from cell text in the first row of the table.
Community Discussions, Code Snippets contain sources that include Stack Exchange Network
Vulnerabilities
No vulnerabilities reported
Install public-apis
You can use public-apis like any standard Python library. You will need to make sure that you have a development environment consisting of a Python distribution including header files, a compiler, pip, and git installed. Make sure that your pip, setuptools, and wheel are up to date. When using pip it is generally recommended to install packages in a virtual environment to avoid changes to the system.
Support
Find, review, and download reusable Libraries, Code Snippets, Cloud APIs from over 650 million Knowledge Items
Find more librariesExplore Kits - Develop, implement, customize Projects, Custom Functions and Applications with kandi kits
Save this library and start creating your kit
Share this Page