waseigo
ExNominatim - A full-featured client for the OpenStreetMap Nominatim API V1
ExNominatim is a full-featured client for the OpenStreetMap Nominatim API V1, with extensive request validation, robust error-handling and reporting, and user guidance with helpful validation messages.
Goals
- Prevent unnecessary calls to the Nominatim API server by validating intended requests and preventing them if the request parameters are invalid.
- Solid error-handling for robustness in production.
- Provide helpful validation messages to the user when a request is deemed invalid.
Features
- Covers the
/search,/reverse,/lookup,/statusand/detailsendpoints. - Utilizes request parameter structs with the appropriate fields (except for
json_callback) for each endpoint. - Validates parameter values prior to the request (possible to override this with the
force: trueoption). - Provides helpful return tuples
{:ok, ...},{:error, reason}and{:error, {specific_error, other_info}}across the board. - Collects all detected field validation errors in an
:errorsfield, and provides a:valid?field in each request params struct. - Can be used with self-hosted Nominatim API instances by setting the
:base_urloption of the enpoint-related functions in theExNominatimmodule. - Automatically sets the
User-Agentheader to “ExNominatim” (plus the version) to comply with the Nominatim Usage Policy.
Installation
The package can be installed from Hex by adding ex_nominatim to your list of dependencies in mix.exs:
def deps do
[
{:ex_nominatim, "~> 1.0.0"}
]
end
Documentation has been published on HexDocs.
Who made this?
Copyright 2024, Made by Isaak Tsalicoglou, OVERBRING in Athens, Attica, Greece.
Many thanks to all the volunteers and contributors of OpenStreetMap and Nominatim.
Most Liked
waseigo
Hi everyone, version 1.1.1 has just been published on Hex: https://hex.pm/packages/ex_nominatim
Here’s the updated documentation: https://hexdocs.pm/ex_nominatim/ExNominatim.html
I have retired the previous versions.
New stuff:
- New
Reportmodule with functions for processing the output of responses into more user-friendly structures and “atomizing” any bitstring keys of maps/structs therein. This is enabled by default and can be switched off independently by setting either or both keywords:process,:atomizetofalsein the endpoint functions. - Implemented validation of a couple remaining fields.
- Various improvements to the DX here and there, such as being able to properly validate setting the value of 0/1 fields to false/true.
I also implemented configurability, i.e.: ExNominatim now takes into account your overarching Elixir application’s configuration, as defined using the Config module. For example, in the config/config.exs file of a Phoenix app called MyApp, you can define default values like so:
config :my_app, MyApp.ExNominatim,
all: [
base_url: "http://localhost:8080",
force: true,
format: "json",
process: true,
atomize: true
],
search: [format: "geocodejson", force: false],
reverse: [namedetails: 1],
lookup: [],
details: [],
status: [format: "json"]
The configuration above has the following effects:
- Requests to all endpoints will use the self-hosted Nominatim API instance at port 8080 of
localhost, accessible over HTTP. - Request parameter validation errors (
valid?: falsein the request parameters struct) will be ignored for requests to all endpoints, except for requests to the/searchendpoint. - Unless requested otherwise in
opts, requests to the/searchendpoint will return data in GeocodeJSON format (instead of the defaultjsonv2). - Requests to the
/reverseendpoint will set:namedetailsto 1 (unless otherwise set inopts). - Requests to the
/statusendpoint will return JSON instead of the default text (HTTP status code 200 and textOKor HTTP status 500 and a detailed error mesage). - The responses from all endpoints will be processed automatically using
ExNominatim.Report.process/1, and any maps and contents thereof (or map contents of structs’s keys) will be converted from bitstring keys to atom keys usingExNominatim.Report.atomize/1(this is the default anyway).
Here’s the preference order:
- The default values for
:base_urland:forceacross all endpoints are the public Nominatim API server’s URL andfalse, respectively. - Any keyword-value pairs set in the
:alllist override these defaults and are applied automatically in requests to all endpoints. - Any keyword-value pairs set in the list of a specific endpoint override any values defined in the
:alllist and are applied automatically in requests to that endpoint. - Anything you set in
optsoverrides all the above.
At any moment you can use ExNominatim.get_config/0 to see the current configuration.
The code is mirrored to my Github account.
Feedback and recommendations welcome!
Popular in Announcing
Other popular topics
Categories:
Sub Categories:
Forums
Popular Tags
- #ecto
- #liveview
- #troubleshooting
- #learning-elixir
- #deployment
- #library
- #erlang
- #testing
- #genserver
- #mix
- #absinthe
- #remote-other
- #otp
- #plug
- #how-to-question
- #macros
- #postgres
- #channels
- #elixirconf
- #exunit
- #discussion
- #code-sync
- #javascript
- #podcasts
- #onsite
- #dialyzer
- #docker
- #authentication
- #umbrella
- #full-time-contract
- #podcasts-by-brainlid
- #ecto-query
- #elixir-ls
- #phoenix_html
- #iex
- #blog-post
- #graphql
- #genstage
- #ai
- #websockets
- #supervisor
- #advent-of-code
- #elixirconf-us
- #distillery
- #processes
- #forms
- #api
- #metaprogramming
- #security
- #performance










