Flag of Ukraine
SymfonyCasts stands united with the people of Ukraine
This course is archived!
This tutorial uses a deprecated micro-framework called Silex. The fundamentals of REST are still ?valid, but the code we use can't be used in a real application.

RESTful APIs in the Real World Course 2

2:18:26

What you'll be learning

This tutorial uses a deprecated micro-framework called Silex. The fundamentals of REST are still ?valid, but the code we use can't be used in a real application.
// composer.json
{
    "require": {
        "silex/silex": "~1.0", // v1.3.2
        "symfony/twig-bridge": "~2.1", // v2.7.3
        "symfony/security": "~2.4", // v2.7.3
        "doctrine/dbal": "^2.5.4", // v2.5.4
        "monolog/monolog": "~1.7.0", // 1.7.0
        "symfony/validator": "~2.4", // v2.7.3
        "symfony/expression-language": "~2.4", // v2.7.3
        "jms/serializer": "~0.16", // 0.16.0
        "willdurand/hateoas": "~2.3" // v2.3.0
    },
    "require-dev": {
        "behat/mink": "~1.5", // v1.5.0
        "behat/mink-goutte-driver": "~1.0.9", // v1.0.9
        "behat/mink-selenium2-driver": "~1.1.1", // v1.1.1
        "behat/behat": "~2.5", // v2.5.5
        "behat/mink-extension": "~1.2.0", // v1.2.0
        "phpunit/phpunit": "~5.7.0", // 5.7.27
        "guzzle/guzzle": "~3.7" // v3.9.3
    }
}

Making RESTful APIs is hard, really hard. There are a lot of concepts to know - resources, representations, HTTP methods, status codes, etc.

Course 1 got us really comfortable with all the terminology. So in episode 2, we're attacking the hard stuff:

  • Using a serializer
  • Token Authentication System (Silex's security system)
  • Hypermedia versus media
  • The HAL hypermedia type
  • The HATEOAS PHP library
  • The HAL Browser
  • Embedding resources (versus adding links)
  • Tricks with Behat for testing API's
  • Pagination and filtering
  • A lot of other pieces in between!

This stuff is not easy. But if you make it through, you'll be armed to attack whatever API need you have.


Your Guides

Ryan Weaver Leanna Pelham

Buy Access

Join the Conversation?

23
Login or Register to join the conversation
Default user avatar
Default user avatar Hikaru Shindo | posted 5 years ago

I'm really looking forward to see this course coming up! Can't wait for it ;)

4 Reply
Default user avatar
Default user avatar Nikos C. | posted 5 years ago

no video download?

3 Reply

Hey!

Sorry for the delay - the video download is up there now.

Cheers!

Reply
Default user avatar

no video download available?

2 Reply
Default user avatar

Any time frame as to when this course will be released?

1 Reply

No timeline currently, but we do have the coding done, which means we're quite far along. Best case-scenario 1 month, but we'll try to release things piece-by-piece. You can press the "Notify Me" button on top and we'll email you when anything comes out :).

Thanks!

Reply
Default user avatar
Default user avatar Luis Lopes | posted 5 years ago

Looking forward to have this covered :) Thanks!!

1 Reply
Default user avatar
Default user avatar Pablo María Martelletti | posted 5 years ago

Hi Guys,

In this post:

http://knpuniversity.com/bl...

you talked about possibly creating 2 tutorials: one for generic PHP and one for Symfony, using FOSRestBundle. I've already been digging in the first screencast, Rest, but I see that this second episode is still not about Symfony. Are still planning to release this Symfony screencast?

Cheers! Thanks a lot for your work! :)

1 Reply

Hi Pablo!

It will be a bit off in the future, but yes, I think it's still something I'd like to do! In these episodes, we'll cover all the real work and knowledge you need for the REST API. A potential future Symfony version would just show you the specific implementation details inside of Symfony. So it wouldn't have all of the meat that these episodes have, but I think it would still be very useful. If you're on our mailing list, we'll definitely let you know.

Cheers and you're very welcome :)

Reply
Maki V. Avatar
Maki V. Avatar Maki V. | posted 5 years ago

You guys - are creating the best tutorials ever! I mean seriously! If this was A TV channel I would start watching TV again and never missed an episode. Hey, let's make a deal - if I find any newblood I will send them immediately here and on your part -> you will keep up good work! :)

1 Reply

Yo Milan V.! You just made our day :). Comment shared in our internal Slack for everyone. Thanks for super nice comment :D :D

Reply
Maki V. Avatar

You are welcome, mate. Just don't forget our bargain, tho! :D

2 Reply
Default user avatar

Just finished Ep1, can't wait for more programmer battle awesomeness! any updates on when Ep2 is out?

1 Reply

Ha, awesome! We're working on ep2 (will be *great*), but it's still at least a few weeks out. Make sure you're subscribed for notifications at the top of this page and we'll shoot you an email.

Thanks!

Reply
Default user avatar
Default user avatar andreas | posted 5 years ago

Hola - the Course 3 ( http://knpuniversity.com/sc... ) does not exist, can help on how do I can learn the documentation part ?

Reply

Hey Andreas,

Womp womp womp... unfortunately, we don't have any courses to cover API docs, but here's a few most popular bundles on GitHub which has good docs will help you with it:
- FriendsOfPHP/Sami
- nelmio/NelmioApiDocBundle
- ApiGen/ApiGen

I hope this helps.

Cheers!

Reply
Default user avatar
Default user avatar Pascal Borreli | posted 5 years ago

little typo here HATOEAS => HATEOAS

Reply

Thanks Pascal! Updated :)

Reply
Default user avatar

Hello Guys, where is the download link ?

Reply

Hi Sergio!

If you own this chapter (or have a subscription), you should see the download link in the upper right on any video page (not this page, but any of the individual chapter pages). If you don't have a subscription, but want to get the source files, you can grab the starting point of the project here: https://github.com/knpunive.... It's on our list to make this an easier download link for non-subscribers :).

Cheers!

Reply
Default user avatar

I need help how to setup an endpoint for this scenario...

I have a resource called Products and the following endpoint returns the list of products: /products.json

Suppose I want to return a representation which contains only a key/pair of the id and name of the product.

e.g:
[
1: 'CD',
2: 'Monitor',
3: 'Keyboard'
]

Should passing a parameter be the correct solution for this?

/product.json?type=list

Reply

Hey Jake!

Ah, philosophical REST questions, they're mostly touch because either nobody has an answer, or the answer makes your life unnecessarily difficult :).

In this case, this is clearly a "Product collection" representation, just not the normal JSON structure that you usually use. So, philosophically, I think it *is* correct to use the same `/product.json` URL that you use for the normal return. Now, *usually* if an endpoint returns different formats, you're supposed to read the Accept header sent by the client. Normally, the use-case is that your API endpoint returns JSON or XML, and the Accept header tells the server which one the client wants. But here, technically, *this* JSON representation and the normal JSON representation are just different "formats" of the same resource. So one "technically" right answer might be that you give this type of response some new Content-Type (e.g. application/vnd.simple-list+json) and read the Accept header to see if they want this format over the normal one.

But in practice, that looks *crazy* to me. Go with your query parameter - it still follows most of these rules, but is also pretty practical. Try to minimize custom things like this, but at the same time, if you're building your API for your *own* consumption (i.e. you're not creating a public API), you can bend the rules a bit more.

Great question - I love (and hate) this stuff! :P

Reply
Default user avatar

Well, just finished my first viewing! Sweet stuff, time to rewatch it and build something now! Congrats guys!

Reply
Cat in space

"Houston: no signs of life"
Start the conversation!

userVoice