plz

command module
v0.2.1 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Jul 29, 2020 License: MIT Imports: 1 Imported by: 0

README

PLZ Rest API

A simple rest API that exposes data related to zip codes and buildings in Berlin.

The source dataset is published by Esri and is available here.

Motivations

Built as an exercise

Rest API

PLZ provides the following endpoints:

  • /status returns the status of the service
  • /zip/buildings returns the number of buildings aggregated by zip code
  • /zip/buildings/history returns the number of buildings aggregated by zip code and year
  • /zip/buildings/:code returns the number of buildings for a specific zip code
  • /zip/buildings/:code/history returns the number of buildings aggregated by zip code and year for a specific zip code

Usage

There are 2 ways to run the PLZ api service: using Docker(recommended) or via manual setup.

For more details about the command line options, use the command plz --help

Docker

The Docker image is available at noandrea/plz, and can be run with

docker run -p 2007:2007 noandrea/plz

The image is built on scratch, the image size is ~9.3mb:

asciicast

Manual setup

Those are the steps to setup the service:

  1. Install plz
go get github.com/noandrea/plz

OR

Download the latest from the release page

  1. Download the dataset linked above:
curl -L https://opendata.arcgis.com/datasets/273bf4ae7f6a460fbf3000d73f7b2f76_0.csv?outSR=%7B%22latestWkid%22%3A3857%2C%22wkid%22%3A102100%7D -o /tmp/src.csv
  1. Massage the dataset to produce an optimized json to be served via the Rest API
plz massage --input /tmp/src.csv --output rest.json
  1. Run the Rest API service
plz serve --data rest.json

asciicast

Examples

Docker compose

docker-compose.yaml example

version: '3'
services:
  plz:
    container_name: plz
    image: noandrea/plz:latest
    ports:
    - 2007:2007

K8s

Kubernetes configuration example:

---
# Deployment
apiVersion: extensions/v1beta1
kind: Deployment
metadata:
  labels:
    app: plz
  name: plz
spec:
  replicas: 1
  revisionHistoryLimit: 3
  selector:
    matchLabels:
      app: plz
  template:
    metadata:
      labels:
        app: plz
    spec:
      containers:
      - env:
        image: noandrea/plz:latest
        imagePullPolicy: Always
        name: plz
        ports:
        - name: http
          containerPort: 2007
        livenessProbe:
          httpGet:
            path: /status
            port: 2007
---
# Service
# the service for the above deployment
apiVersion: v1
kind: Service
metadata:
  name: plz-service
spec:
  type: ClusterIP
  ports:
  - name: http
    port: 80
    protocol: TCP
    targetPort: http
  selector:
    app: plz

Documentation

Overview

Copyright © 2020 Andrea Giacobino <no.andrea@gmail.com>

Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:

The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.

Directories

Path Synopsis

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL