Code Monkey home page Code Monkey logo

sl-php-assignment's Introduction

sl-php-assignment Build Status codecov

This project houses a basic PHP project that allows for storage and retrieval of a blob value.

Please take a look at notes.md

Pre-requisites

  • PHP >= 7.2
  • Composer
  • MySQL
  • Docker (For Development)

Local Development

For local development you may use docker compose to setup a running environment. The default port runs on 8080.

> docker compose up

Unit Tests

To run unit tests, make use of the PHPUnit library that comes together with it

> ./vendor/bin/phpunit --testsuite unit-test

Test coverage results are output in the repository's root location clover.xml.

DB Structure

Do take a look at any files located in the /mysql folder.

API Design

  • GET /api/v1/objects
Examples

-- Empty database --

GET /api/v1/objects
Response - 200 OK 
{}

-- Has some values --

GET /api/v1/objects
Response - 200 OK
{
    "foo": "bar",
    "baz": "fizz"
}
  • GET /api/v1/objects/{key}
    • Accepted query params: timestamp=<int>
Examples

-- Successful --

GET /api/v1/objects/foo
Response - 200 OK 
bar

GET /api/v1/objects/baz
Response - 200 OK
Header - Content-Type: application/json
{
    "foo": "bar"
}

GET /api/v1/objects/baz?timestamp=1634219586
Response - 200 OK
some earlier val

-- Invalid Timestamp --

GET /api/v1/objects/baz?timestamp=not+integer
Response - 400 Bad Request
{
    "error": "Invalid timestamp given."
}

-- Not Found -- 

GET /api/v1/objects/idontexist
Response - 404 Not Found
{
    "error": "Key was not found."
}
  • POST /api/v1/objects
    • Accepted headers: Content-Type: application/json
Examples

-- Successful --

POST /api/v1/objects -d '{"key": "foo"}'
Response: 200 OK
{
    "timestamp": 1634219586
}

POST /api/v1/objects -d '{"key": "baz", "another": "bar"}'
Response: 200 OK
{
    "timestamp": 1634219886
}

-- Bad Request --

POST /api/v1/objects -d 'not json'
Response: 400 Bad Request
{
    "error": "Malformed JSON payload received."
}

POST /api/v1/objects -d '{"key":"""multi qu"ote"}'
Response: 400 Bad Request
{
    "error": "Malformed JSON payload received."
}

POST /api/v1/objects -d ''
Response: 400 Bad Request
{
    "error": "Empty payload received."
}

sl-php-assignment's People

Contributors

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