Skip to content
This repository was archived by the owner on Dec 17, 2019. It is now read-only.

Lucky-Loek/Symfony-API-Example

Repository files navigation

Symfony API Example

Build Status StyleCI

A small example of how an API could be written in Symfony. This project allow a user to receive/add/update/delete cars.

All output is standardized so that it is easy to parse in any language on any environment.

Features

URLS

// GET
symfony.app/car

// GET by id
symfony.app/car/{id}

// POST new
symfony.app/car

// PATCH update
symfony.app/car/{id}

// DELETE remove
symfony.app/car/{id}

Installation

Requirements

  • PHP >= 7.1
  • Composer
  • MySQL >= 5.5

Commands

  1. Clone this repo
  2. Run composer install
  3. Run php bin/console doc:mig:mig
  4. Run php bin/console doc:fixtures:load

Testing

  1. Run php bin/console doc:mig:mig --env=test
  2. Run composer test

For more information which tests are run, please refer to the "test" section of composer.json

Technical Docs

GET all entities

# Request
$ curl --request GET \
    --url http://symfony.app/car
  
# Response
[
    {
        "id": 1,
        "brand": "Ford",
        "name": "Mustang",
        "year": 1972
    },
    {
        "id": 2,
        "brand": "Toyota",
        "name": "Corolla",
        "year": 1983
    },
    
]

GET entity by id

# Request
$ curl --request GET \
    --url http://symfony.app/car/1
  
# Response
{
    "id": 1,
    "brand": "Ford",
    "name": "Mustang",
    "year": 1972
}

POST new entity

# Request
$ curl --request POST \
    --url http://symfony.app/car \
    --header 'content-type: application/json' \
    --data '{
	  "brand": "Ford",
	  "name": "Mustang",
	  "year": 1972
  }'
  
# Response
{
    "id": 1,
    "brand": "Ford",
    "name": "Mustang",
    "year": 1972
}

PATCH update existing entity

# Request
$ curl --request PATCH \
    --url http://symfony.app/car/1 \
    --header 'content-type: application/json' \
    --data '{
      "year": 2016
  }'
  
# Response
{
    "id": 1,
    "brand": "Ford",
    "name": "Mustang",
    "year": 2016
}

DELETE remove existing entity

# Request
$ curl --request DELETE \
    --url http://symfony.app/car/1

# Response
{
    "message": "Car deleted"
}

About

Example project of how a Symfony 3 API could be set up.

Topics

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published