Giter Site home page Giter Site logo

aprendiendonode / geonames-api-mezzio Goto Github PK

View Code? Open in Web Editor NEW

This project forked from mariojrrc/geonames-api-mezzio

0.0 1.0 0.0 2.72 MB

GeoNames Api example written in PHP 7.4 with Mezzio and MongoDB

License: BSD 3-Clause "New" or "Revised" License

PHP 99.58% HTML 0.42%

geonames-api-mezzio's Introduction

GeoNames API Mezzio/MongoDB Example

Build Status

This project is an example of REST API written in PHP 7.4 that makes use of Mezzio framework, MongoDB and Redis for cache.

It basically has two endpoints that allow us to perform some CRUD operations:

  • /v1/state
  • /v1/city

The endppoints are protected by authorization header tokens in the following format X-Api-Key: uuid. It has two types of tokens defined in the file .env on project's root folder. One token is to perform some "Admin level" operations, such as create, update and delete. And the other one is to perform only read operations.

Note: Tokens have rate-limit params setted up. You can configure them in config/autoload/api-credentials.global.php file. By default, it allow us to perform 100 requests per second.

DOCS

The endpoint's documentation is located in public/doc folder. It was written on top of OpenAPI v3 notation.

Running the project

OBS: PHP 7.4, MongoDB, Redis extensions are requeried

  1. Rename the file .env.dist to .env and fill out the required info
  2. Run composer install
  3. Run composer serve
  4. Make calls to the endpoints via Postman or similar in the following address 0.0.0.0:8080/v1/state

Using it with Docker

  1. docker-compose up
  2. docker exec -t geoname-mezzio-php bash -c "cd /var/www/html && composer install" Obs: If you have problem with mongodb extension when composer installing, run docker exec -t geoname-mezzio-php bash -c "pecl install mongodb"

BONUS There's a console command to create brazilian states and cities available through php bin/console populate:geodb command;

Live Demo

You can check the api and its documentation live on Heroku by clicking here. A simple front-end to list cities and states can be found here.

CI/CD

There is a configured pipeline in SemaphoreCI to run some code style validations (PHPCS and PHPStan) and Unit tests. After a successful build, it deploys the code to Heroku servers. For monitoring, the heroku app makes use of the Newrelic add-on.

Questions and Suggestions?

Drop me an e-mail

TODO

  • Fetch api tokens from database (cached) in order to keep it more easly to mantain
  • Create more unit tests to have a 100% coverage score.

geonames-api-mezzio's People

Contributors

mariojrrc avatar

Watchers

James Cloos avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.