Symfony RESTful API: Course 1

In this series, we get to work: by building the same API in the REST series, but leveraging all the amazing tools and libraries of the Symfony framework. If terminology like representations, resources, and hypermedia are new to you, start with the REST series and then come back. And get ready to get your (API) mind blown.

In Course 1, we'll start quick with:

  • Build your first functional POST endpoint
  • Decoding the Request body
  • Using forms to handle incoming data
  • Writing tests for your API
  • Handling data "seeding" for your tests
  • GET, PUT, DELETE and PATCH endpoints
  • Using the JMS Serializer

Your Guides

Ryan Weaver Leanna Pelham

Questions? Conversation?

  • 2016-06-18 weaverryan

    Hey Filipe!

    You're absolutely right - and we move them into the BaseController eventually (once we actually need them in multiple places - actually it's something we do "offline" between episodes 4 and 5). Of course, many people - like you - will already know this will need to happen, so you can put it directly into BaseController :).

    Cheers!

  • 2016-06-16 Filipe Moraes

    Why the methods "processForm" , "getErrorsFromForm" and "throwApiProblemValidationException" are not within the class "BaseController"? These methods are common to all controllers.

  • 2016-02-29 weaverryan

    Hi there!

    You absolutely *can* just return HTML in your API instead of JSON - it's often an easy shortcut to make updating your HTML page with AJAX really easy. Here's how it would look:

    public function someAction()
    {
    $html = $this->renderView('mypage/some_template.html.twig', array('twigVar' => 'twigVal'));

    // return pure HTML
    return new Response($html);
    // or return HTML inside JSON, under an "html" key (but this key could be anything).
    return new JsonResponse(array('html' => $html));
    }

    Cheers!

  • 2016-02-29 ibn mrabet achraf

    hey guys,
    how to get a twig.html page as response in api Controller for example: I get information from the user then i want to display a html page containing those information !

  • 2015-08-25 Michael Tacelosky

    +1 for a tutorial that uses FOSRestBundle and Angular.

  • 2015-06-22 Victor Bocharsky

    There is a lot of information about REST on KnpU. I think I better to start from scratch and I'm almost sure there I discover a useful information for me too. I always open something new for myself with your screencasts. They're a very cognitive and helps to improve the understanding of the subject area! Thanks!

  • 2015-06-22 weaverryan

    Hey Bocharsky!

    You can start right with this one :). If you're quite new to REST/API stuff and really want to go deep, I'd watch the other one - though in this screencast, we occasionally say "if you want more info, go to this URL to watch part of the REST series" - to help out with this.

    Cheers!

  • 2015-06-22 Victor Bocharsky

    Hey Ryan! Do I need to finished "RESTful APIs in the Real World" courses first to start this course for Symfony? Does this courses closely connected?

  • 2015-05-21 weaverryan

    I think FOSRestBundle is a bit like FOSUserBundle - you can use it, or you can fairly easily build that same stuff yourself and get more flexibility. No one option is best - using the bundle gets you setup faster of course :).

    BazingaHateoasBundle is *wonderful*, and we will use it later in the series. The question here is, do you really need links in your API? They're all the rage, but it depends on who you're building your API for (e.g. if your API is for your JS frontend, maybe you don't need links, or need very few).

    Cheers!

  • 2015-05-21 Nick

    Thanks for reply, for a real application though is FosRestBundle and
    BazingaHateoasBundle recommended or you think without those you can create a real life professional application without issues and clean enough?

  • 2015-05-21 weaverryan

    Hey Nick!

    Good question! The FosRestBundle is basically a set of various tools - like helping you decode the JSON request, helping serialize the Form errors, doing content-type negotiation and adding a view layer. These are all peripheral tools - and when you get building, you find that you need probably only a few of those. I don't use it in the screencast, though I could have for JSON deserialization and a few other minor things.

    Cheers!

  • 2015-05-21 Nick

    Hey! Why not use FosRestBundle? Or maybe this will be in episode 2?

  • 2015-05-16 weaverryan

    Hey!

    On Angular, no plan yet - but I'm going to see if anything angular-specific might be nice to cover as an addendum to this series. I mean, you'll be rocking a very solid API after this series, but if there are any tweaks needed to play even nicer with Angular, maybe we can add something for that after.

    The good news is that we're releasing this series right now - expect more next week.

    Cheers!

  • 2015-05-15 prasath_s

    Ye Angular would be great! Any news on that front? And also when you are planning to publish the series? Cheers:)

  • 2015-05-13 prasath_s

    Cant wait either:) Hope that more of this series is soon to be released!!:)

  • 2015-04-23 Ghulam Kibria Ali

    Can't wait for this course! :D

  • 2015-03-25 twomartoe

    Eagerly awaiting this too, in the meantime, check this out

    https://codereviewvideos.com/c...

  • 2015-03-19 weaverryan

    Hey Nick!

    We haven't started on this yet, but it's up next - so it's still at least several weeks away. YES, it will use FOSRestBundle. I'm not sure about angular yet - but I think it might be a good idea - after all, that's what a lot of people are using to consume those APIs.

    Cheers!

  • 2015-03-19 Nick

    Any estimate? Will you use angular and fosrestbundle for this?