GithubHelp home page GithubHelp logo

lumen-products-api-exercise's Introduction

Lumen Products API exercise

ci

A simple implementation of Lumen as a 'products' API.

The Brief

Build a RESTful web application with the following API endpoints. Data should persist to a sql database.

API Endpoints

POST /products
[
    {
        "sku":"abc",
        "attributes": {
            "size": "small",
            "grams":"100",
            "foo":"bar"
        }
    }
]

"attributes" can contain any key value. "sku" is unique.

GET /products
Returns a list of products
[
    {
        "sku":"abc",
        "attributes": {
            "size": "small",
            "grams":"100",
            "foo":"bar"
        }
    },
    ...
]

The implementation details

  • API structure implemented as outlined above.
  • Data persists to a MySQL db while the db image is running.
  • Database is seeded with the product/attributes per the example.
  • No external libraries included outside of the base lumen setup.

Performance and scaling considerations

While there's nothing too special, there are some items worth noting:

  • I find the MVC approach to work exceptionally well in these data access layer type applications, as maintenance and extension is made easy with how each component is split into their own domains (routing, db access, formatting).
  • Lumen was also a conscious choice over the typical Laravel setup as it is more lightweight and has faster response times.
  • Database drivers are plug and play, with lumen supporting four out of the box (MySQL, PostgreSQL, SQLite, and SQL Server).
  • As this is containerized we can build and deploy with ease on any host/cloud with a container runtime.

Running the service

Build the app image.

$ docker-compose build app

Start up the app image.

$ docker-compose up app
...
ERROR 2002 (HY000): Can't connect to server on 'db' (111)
ERROR 2002 (HY000): Can't connect to server on 'db' (111)

   INFO  Dropped all tables successfully.


  Dropping all tables ................................................................................................................... 370ms DONE

   INFO  Preparing database.

  Creating migration table .............................................................................................................. 268ms DONE

   INFO  Running migrations.

  2023_01_19_141213_create_attributes_table .............................................................................................. 89ms DONE
  2023_01_19_141213_create_product_table ................................................................................................ 209ms DONE


   INFO  Seeding database.

  Database\Seeders\ProductSeeder ........................................................................................................... RUNNING
  Database\Seeders\ProductSeeder .................................................................................................... 197.05 ms DONE

  Database\Seeders\AttributesSeeder ........................................................................................................ RUNNING
  Database\Seeders\AttributesSeeder .................................................................................................. 30.60 ms DONE

[Tue Jan 24 15:44:31 2023] PHP 8.1.14 Development Server (http://0.0.0.0:8000) started

You should now be able to view the initially seeded product at http://localhost:8000/products.

To cleanly shutdown, run docker-compose down regardless of whether it was shut down with ^C.

Running the tests

Similar to how you run the service, build the test image.

$ docker-compose build test

Run the test image.

$ docker-compose run test

Lumen PHP Framework

Build Status Total Downloads Latest Stable Version License

Laravel Lumen is a stunningly fast PHP micro-framework for building web applications with expressive, elegant syntax. We believe development must be an enjoyable, creative experience to be truly fulfilling. Lumen attempts to take the pain out of development by easing common tasks used in the majority of web projects, such as routing, database abstraction, queueing, and caching.

Official Documentation

Documentation for the framework can be found on the Lumen website.

Contributing

Thank you for considering contributing to Lumen! The contribution guide can be found in the Laravel documentation.

Security Vulnerabilities

If you discover a security vulnerability within Lumen, please send an e-mail to Taylor Otwell at [email protected]. All security vulnerabilities will be promptly addressed.

License

The Lumen framework is open-sourced software licensed under the MIT license.

lumen-products-api-exercise's People

Contributors

andbeav 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.