Code Monkey home page Code Monkey logo

challenge-bravo's Introduction

Hurb Challenge Bravo

Build Status

This project is an example of REST API written in PHP 7.4 to handle currency conversion. It is result of the Hurb Challenge Bravo. The project makes use of Swoole to handle at least 1000 requests per second. It also uses Crypto Compare API to fetch data from.

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

  • /v1/exchange/{fromCurrency}/{toCurrency}/{amount}
  • /v1/currency

The endpoints 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 committed to this repo for are for testing purpose only. For production environment, credentials should not be available in your version control. Note: Tokens have rate-limit params defined. You can configure them in config/autoload/api-credentials.global.php file. By default, it allow us to perform 2000 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

Using it with Docker

  1. docker-compose up
  2. docker exec -t challenge-bravo-php bash -c 'PHINX_DBHOST=challenge-bravo-mysql PHINX_DBUSER=mario PHINX_DBPASS=mariocosta ./vendor/bin/phinx migrate'
  3. Make calls to the endpoints via Postman or similar in the following address 0.0.0.0:8080/health to check if it's live.

** Using without docker. OBS: PHP 7.4, MySQL, and Swoole extensions are required**

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

CI/CD

There is a configured pipeline in SemaphoreCI to run some code style validations (PHPCS and PHPStan) and Unit tests.

Questions and Suggestions?

Drop me an e-mail

TODO

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

challenge-bravo's People

Contributors

m4n3z40 avatar mariojrrc avatar rodrigosdo avatar zanaca avatar

Watchers

 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.