Overpass API - How to get all sustance amenities - overpass-api

I am using the Overpass API in order to fetch all the amenities. All the amenities are listed on the OSM wiki: Amenities.
I cannot seem to get this to work. I first have tried "amenity"="pub;bar;restaurant". But this does not work and I need to type out all the types. I have also tried "amenity"="sustenance" and "amenity"="pub~restaurant~bar". But none of these return any values.

See the OSM Wiki regarding Overpass QL, especially the section about Value matches regular expression. The syntax is a little bit different from the one you tried. Overpass API by Example is also often helpful and has multiple examples for using regular expressions with multiple values.
The correct query would be: highway~"^(pub|bar|restaurant)"

Related

REST API filter queries - handling OR operations

I am trying to create a nice helper class to parse some query parameters so they can be used to filter an array of data.
I am using the following syntax for my query parameters:
?filter[name,contains,string]=foo // name field contains the string "foo"
?filter[id,gte,number]=123 // item field is greater then or equal to 123
?filter[type,eq,string]=foo|bar // type field is equal to "foo" or "bar"
(you can also use , between the values to act as an AND operator, but on a single field, it doesn't have many use cases eg gt 1 AND 2 isn't a great filter)
These query params can be combined, eg
?filter[name,contains,string]=foo&filter[id,gte,number]=123
And this will act as an AND condition, meaning data is returned that matches both filters.
Great so far. But I want to implement an OR condition for multiple separate filters.
?filter[]=... is used for the actual filter query, so I can't really use that to set the OR condition.
I've tried finding REST API implementations that use somethig similar to this filtering syntax, the closest is Laravel, but the docs don't go into any details about it.
Hoping someone can point me to a good resource about REST API filtering/help me figure out a nice way to implement the OR condition.
Unfortunately I think if you want the flexibility you're looking for, it'll probably be best to define a proper grammar and accept a "filter string" that follows that syntax. This would mean you have to define the grammar and behavior of defaults, parse it, and turn it into a query that matches your underlying storage system (e.g., a SQL query or ORM API calls).
For example, this might make your filters look something like:
?filter=name:("foo" AND id >= 123) OR id <= 567
And it turns out that there's quite a lot to decide when you start introducing complex filtering operations.
For more reading, Google's API filtering syntax and guidelines are: https://google.aip.dev/160 and the EBNF grammar is https://google.aip.dev/assets/misc/ebnf-filtering.txt

How can I specify multiple languages when sending a GET request to GitHub search API

I wonder how can I send a GET request to GitHub search API, specifically https://api.github.com/search/repositories and make the query to include several languages instead of one.
Here's my current query.
https://api.github.com/search/repositories?q=stars:%3E=1000+language:scala&sort=stars&order=desc&per_page=10
I have tried doing something like this but it didn't work as well
https://api.github.com/search/repositories?q=stars:%3E=1000+language:[scala, java]&sort=stars&order=desc&per_page=10
Thanks for your help
You need to pass in multiple language: element for being able to pass multiple languages to the query as per the doc.
For your specific case, the query would be :
https://api.github.com/search/repositories?q=stars:%3E=1000+language:scala+language:java&sort=stars&order=desc
with pagination applied it would be :
https://api.github.com/search/repositories?q=stars:%3E=1000+language:scala+language:java&sort=stars&order=desc&per_page=10
However, with pagination applied your search results will be limited in the browser.

Google nearby search with multiple keywords

Im trying to fetch both restaurants and cafes from googles Places API using the nearby search query.
Excerpt from my query string:
...&radius=2000&keyword=cafe+restaurant&key=myAPIKey
Using the plus '+' seems to bias towards one keyword type and returns a very limited quantity of places (limited versus using i.e. the restaurant and the cafe keywords on separate queries).
I've also tried using single pipe, %20, double pipe to name a few but nothing seems to work.
I've looked at this SO thread, the solution here (its 7 years old now) uses a workaround making two separate calls which I was hoping has now been resolved within the query string?
Is it possible to query nearby search for two keywords i.e. cafe and restaurant using a single query string?
No, it is not possible. You need to make multiple requests to the API for this, one with keyword=cafe or type=cafe, and the other with keyword=restaurant or type=restaurant.
You may also want to file a feature request for this in Google's Issue Tracker.
Hope this helps!

Pass multiple filters with multiple values in a query string (REST)

I originally posted multiple filters containing multiple values in JSON as part of my GET request but I believe this is bad practise, so I changed it to a POST but I don't like it as getting results from a query has nothing to do with a POST so I guess I'll have to use a query string
Most filter examples I have found are either using one filter or one value, but I am looking as to whether or not there is a best practise to pass multiple filters with multiple values for filtering as a single parameter in the query string.
For example, this is a basic one which looks for all cars that are red
GET /cars?color=red
But what if I wanted to look for all cars that are
red, blue or green and
have 2 seats or less and
their brand name starts with b and
can be bought in the US, UK or Germany
Would the following be ok?
http://myserver/api/cars?color=red|blue|green¬seats<=2¬brand[startswith]b¬country=USA|UK|Germany
I'm suggesting the use of the:
| character as a separator between each values for a given filter
¬ character as a separator between each filters
[startsWith] to handle the search type, but could contain [=, <=, >=, <>, [contains],[endswith], etc...
This would then be parsed in the server end and the relevant filters would be build accordingly based on the provided values
Hope this make sense but I'm really interested as to whether or not there is a standard/best practise used for such scenarios with REST in mind?
Thanks.
As in most design questions, the key is having a consistent design for all your APIs. You can follow certain well-known guidelines/standards to make your API easily discoverable.
For example, take a look at OData. The "Queries" section on this page is relevant to your question. Here's an example:
https://services.odata.org/v4/TripPinServiceRW/People?$top=2 & $select=FirstName, LastName & $filter=Trips/any(d:d/Budget gt 3000)
Another option is the OpenSearch standard. The relevant section is here. Here's an example:
https://opensearch.php?recordSchema=html&query=dc.creator any Mill* Grad*
Another interesting option is GraphQL, which makes it easier to map query parameters to data fetch parameters. It uses a filter payload instead of query parameters. See the spec here: GraphQL Spec.

Ckan API, List more information on rest dataset

I am using ckan 2.6.0
According with the documentation: http://docs.ckan.org/en/latest/api/legacy-api.html
I am trying to use the endpoint /rest/dataset and works (only for public data but works), it only returns an array of datasets names, and nothing else, an example can be found here http://demo.ckan.org/api/1/rest/dataset
Is there a way to get a complete listing for datasets ? I also tried the search endpoint and returns the same array.
For example I would like to get the title, description, tags, file types, etc, like in the image below:
The REST api is deprecated/unmaintained and has been for a long time. Follow the up-to-date API documentation here.
package_search is your best bet: http://demo.ckan.org/api/action/package_search
That gives you a batch of datasets. Get more by paging through using the 'start' and 'rows' parameters.
If you simply want them all, then it's much better still to use a bulk download that some sites offer, such as data.gov.uk, which supplies it complete as a simple JSONL download: Meta-data for data.gov.uk datasets.