Code Monkey home page Code Monkey logo

routeclass's Introduction

Route Class

The class Route simulates a http request and response as would come from an API. The entry point routes.php in the base dir. Since this is not run using a webserver this code takes the cases in the nested and unnested routes and runs them through routes.php. To get and run the project

git clone https://github.com/parthamittra/routeClass.git

composer install

php routes.php

The requests (in the routes.php file with a Request object) will then output the json responses.

Problem Statement

Using modern PHP (think PHP7, composer, autoloading, PSR-4, and best practices) please create a "Routing Class" as defined below.

A routing class is designed to take a url segment and automatically invoke a controller class. It does this by breaking up the url segments that come in a predictable pattern and invoking the correct class and method and inserting parameters into the method invoked. We will be following a REST-ful convention and be using common http methods. Your Routing class will be aware of the http method and the actual url segment.

Here is the complete requirement. These tables represents all possible routing logic.

Unnested routes

Method Segment Controller class name Controller method name Parameters
GET /patients PatientsController index none
GET /patients/2 PatientsController get this should invoke get($patientId) where $patientId = 2
POST /patients PatientsController create none (extra credit for handling the request body)
PATCH /patients/2 PatientsController update update($patientId)
DELETE /patients/2 PatientsController delete delete($patientId)

Nested routes

Method Segment Controller class name Controller method name Parameters
GET /patients/2/metrics PatientsMetricsController index index($patientId)
GET /patients/2/metrics/abc PatientsMetricsController get get($patientId, $metricId)
POST /patients/2/metrics PatientsMetricsController create create($patientId)
PATCH /patients/2/metrics/abc PatientsMetricsController update update($patientId, $metricId)
DELETE /patients/2/metrics/abc PatientsMetricsController delete delete($patientId, $metricId)

To invoke the Routing class we'll be calling it statically. For example we'll be defining a routes.php that looks like this

Route::resource('patients');
Route::resource('patients.metrics');

routeclass's People

Contributors

parthamittra avatar

Watchers

James Cloos avatar  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.