|
| 1 | +# RESTful Webservices in Symfony |
| 2 | + |
| 3 | +## [Jan Schädlich](http://janschaedlich.de) | Team Lead PHP Development @ Siemens Mobility Portugal |
| 4 | + |
| 5 | +### Workshop @ SymfonyWorld Online Winter Edition 2021 on 7th of December 2021 |
| 6 | + |
| 7 | +> Nowadays RESTful APIs are powering the web and are used in almost every web application. |
| 8 | +> In this workshop you will learn the fundamental principles of REST and how you can implement a RESTful application using Symfony. |
| 9 | +> |
| 10 | +> We will start with the basics of REST and will cover some more advanced topics like Serialization, Content-Negotiation, Security afterwards. |
| 11 | +> Besides all the theory you can deepen your learnings on every topic while doing the provided coding challenges. |
| 12 | +> |
| 13 | +> In addition to an IDE (or text editor) you need a current version of PHP, Composer and Symfony CLI. |
| 14 | +
|
| 15 | +Code written for the "RESTful Webservices in Symfony" workshop @ SymfonyWorld Online Winter Edition 2021. |
| 16 | + |
| 17 | +This is example code that is not production-ready. It is intended for studying and learning purposes. |
| 18 | + |
| 19 | +(c) 2021 Jan Schädlich All rights reserved. |
| 20 | + |
| 21 | +## Installation |
| 22 | + |
| 23 | + # checkout the project |
| 24 | + $ git clone git@github.com:jschaedl/RESTful-Webservices-in-Symfony.git |
| 25 | + |
| 26 | + # initialize dev environment |
| 27 | + $ make dev-init |
| 28 | + |
| 29 | + # start webserver |
| 30 | + $ symfony serve -d |
| 31 | + |
| 32 | +## Tools |
| 33 | + |
| 34 | +- Symfony Binary: https://symfony.com/download |
| 35 | +- Postman App: https://www.getpostman.com/downloads |
| 36 | + |
| 37 | +## Coding Challenge |
| 38 | + |
| 39 | +For a 2-day conference, workshops and participants must be recorded. |
| 40 | +Each workshop last one day. |
| 41 | +All workshops have a participation limit of 25 people. |
| 42 | +Each attendee can only take part in one workshop per day. |
| 43 | + |
| 44 | +We are going to build an API that can be used to organize workshops. |
| 45 | +Our API should offer the following basic features: |
| 46 | + |
| 47 | +- List all workshops |
| 48 | +- Read a single workshop |
| 49 | +- Create a workshop |
| 50 | +- Update a workshop |
| 51 | +- Delete a workshop |
| 52 | +- List all attendees |
| 53 | +- Read a single attendee |
| 54 | +- Create an attendee |
| 55 | +- Update an attendee |
| 56 | +- Delete an attendee |
| 57 | +- Add an attendee to a workshop |
| 58 | +- Remove an attendee from a workshop |
| 59 | +- The listing of workshops and attendees should support pagination |
| 60 | +- The API should support JSON and XML |
| 61 | + |
| 62 | +We also want to limit access to our API as follows: |
| 63 | + |
| 64 | +- Listing of all workshops is allowed for everyone |
| 65 | +- Reading a single workshop is only allowed for logged-in users with the `ROLE_USER` role |
| 66 | +- Creating and updating a workshop is only allowed for logged-in users with the `ROLE_USER` role |
| 67 | +- Deleting a workshop is only allowed for logged-in users with the `ROLE_ADMIN` role |
| 68 | +- Listing of all attendees is allowed for everyone |
| 69 | +- Reading a single attendee is only allowed for logged-in users with the `ROLE_USER` role |
| 70 | +- Creating and updating a attendee is only allowed for logged-in users with the `ROLE_USER` role |
| 71 | +- Deleting an attendee is only allowed for logged-in users with the `ROLE_ADMIN` role |
| 72 | +- Adding/removing an attendee to/from a workshop is only allowed for logged-in users with the `ROLE_USER` role |
| 73 | + |
| 74 | +## Endpoints |
| 75 | + |
| 76 | +### Workshop |
| 77 | + |
| 78 | +HTTP Method | Endpoint |
| 79 | +----------- | -------- |
| 80 | + GET | /workshops |
| 81 | + POST | /workshops |
| 82 | + GET | /workshops/{workshopId} |
| 83 | + PUT | /workshops/{workshopId} |
| 84 | + DELETE | /workshops/{workshopId} |
| 85 | + POST | /workshops/{workshopId}/attendees/{attendeeId}/add |
| 86 | + POST | /workshops/{workshopId}/attendees/{attendeeId}/remove |
| 87 | + |
| 88 | +### Attendee |
| 89 | + |
| 90 | +HTTP Method | Endpoint |
| 91 | +----------- | -------- |
| 92 | + GET | /attendees |
| 93 | + POST | /attendees |
| 94 | + GET | /attendees/{attendeeId} |
| 95 | + PUT | /attendees/{attendeeId} |
| 96 | + DELETE | /attendees/{attendeeId} |
| 97 | + |
| 98 | +## Testing |
| 99 | + |
| 100 | +We will add functional tests using a snapshot testing approach to make sure that our endpoints are working correctly. |
| 101 | + |
| 102 | + # run the test suite |
| 103 | + $ make phpunit |
0 commit comments