Skip to content

Dafkey/sepomex-api

 
 

Repository files navigation

SepomexAPI

Simple API for Sepomex zip codes using Sepomets under the hood.

You can see this at: https://elixir-sepomex-api.herokuapp.com/

Only for reference.

Requirements

  1. asdf
  2. Docker (optional)

You can run asdf install in the root folder of the project to install the required versions of Erlang and Elixir defined in the .tool-versions file.

Run in local

  1. Clone this repository git clone git@github.com:Plus17/sepomex-api.git
  2. Go to the project dir cd sepomex-api
  3. Install dependencies: mix deps.get && mix deps.compile
  4. Run: mix run --no-halt

Now server is running at: http://localhost:4001/

Build docker image

  1. Build image: docker build . --tag sepomex_api
  2. Run docker images to get the id of the new image.
  3. Run: docker run --env PORT=80 -p 8081:80 <image-id>

Now docker image is running at: http://localhost:8081/

Usage

Make a get request to service with the zip code: GET: http://localhost:8081/03100

❯ curl "http://localhost:8081/03100" | jq --indent 2
  % Total    % Received % Xferd  Average Speed   Time    Time     Time  Current
                                 Dload  Upload   Total   Spent    Left  Speed
100   630  100   630    0     0   205k      0 --:--:-- --:--:-- --:--:--  205k
[
  {
    "city": {
      "code": "03",
      "name": "Ciudad de México"
    },
    "municipality": {
      "code": "014",
      "name": "Benito Juárez"
    },
    "office": "03001",
    "postal_code": "03100",
    "settlement": {
      "code": "0496",
      "name": "Del Valle Centro"
    },
    "settlement_type": {
      "code": "09",
      "name": "Colonia"
    },
    "state": {
      "code": "09",
      "name": "Ciudad de México"
    },
    "zone": "Urbano"
  },
  {
    "city": {
      "code": "03",
      "name": "Ciudad de México"
    },
    "municipality": {
      "code": "014",
      "name": "Benito Juárez"
    },
    "office": "03001",
    "postal_code": "03100",
    "settlement": {
      "code": "2624",
      "name": "Insurgentes San Borja"
    },
    "settlement_type": {
      "code": "09",
      "name": "Colonia"
    },
    "state": {
      "code": "09",
      "name": "Ciudad de México"
    },
    "zone": "Urbano"
  }
]

image

How to update the zip codes database

  1. Download the last database in TXT format from correosdemexico.gob.mx
  2. Rename the file to sepomex.zip
  3. Replace the file in priv/sepomex.zip
  4. Deploy

About

Sepomex API writen in Elixir

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages

  • Elixir 91.2%
  • Dockerfile 8.8%