-
-
Notifications
You must be signed in to change notification settings - Fork 5.2k
Add new articles about REST APIs #5260
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Comments
+1 for this |
+1! |
It will be useful 👍 |
As I don't have a lot of REST experience, I would be happy if people could indicate what exactly will be usefull. What are the problems you're facing with REST in Symfony? Where did you find help? What would you like to see in the official docs? |
i think we should split this to a bunch of different articles. |
Yes, you're right, it's a quite complex. |
Best advice: start small - the previous effort was huge. A short tutorial showing the following would go along way: A) Controller route methods It is indeed such a big complex thing, that I think it's paralyzing. Whenever we give an example anywhere, we should think about using a template sometimes, and making something an "API" endpoint in another. |
+1 |
2 similar comments
👍 |
+1 |
This is a huge, and not-well-defined task. In general, we need to be more API-centric in the docs, but I don't think anyone is going to take the time to create a huge new section (unless I or a few core contribs find time to do it). For those that are looking here, I worked/am working on http://knpuniversity.com/screencast/symfony-rest. The scripts are free and the code-blocks below are expandable so you can get a full context. If there are parts of this that people would specifically find useful in the core docs, I'd be happy to help bring those over. Start with small, executable goals :). |
I'm copying below a comment from @michaelperrin about this in a duplicated issue that we closed. With the rise of APIs and service-oriented architecture, it would be great to have a starting point on how to build REST APIs with Symfony and some third-party bundles making it easier. A step-by-step example would be appropriate, with an API built upon a simple entity (with a least one relation), with the main operations (create, update, delete, show, search) being impletend. The following subjects could be mentioned:
Should the API be built with Dunglas Core Api Bundle or FOSRestBundle? I like the pragmatic approach of Dunglas Bundle and the strong focus on standards, but I have no experience with it yet, and it may be out of the scope of the main Symfony documentation. We should either way choose one very pragmatic approach, so that users don't get confused and overwhelmed by the many possibilities. Other possibilities could however be mentioned. I'm also asking for help in the Symfony Slack to see if some truly expert in Symfony + APIs can share with us the modern best practices about that so we can start writing some articles. Thanks! |
Here's my humble contribution, a bullet list of the steps we follow to create a new endpoint:
We might need to create some event listeners (to populate The endpoint's logic is then up to us, it doesn't have to be done in a "Symfony" way. For example we can:
Here's an example of such a controller: <?php
// src/AppBundle/Controller/Api/FortuneController.php
namespace AppBundle\Controller\Api;
use AppBundle\Service\SubmitNewFortune;
use AppBundle\Service\SubmitNewFortuneHandler;
use Symfony\Component\HttpFoundation\Request;
use Symfony\Component\HttpFoundation\Response;
class FortuneController
{
private $submitNewFortuneHandler;
public function __construct(SubmitNewFortuneHandler $submitNewFortuneHandler)
{
$this->submitNewFortuneHandler = $submitNewFortuneHandler;
}
public function submit(Request $request): Response
{
$submitNewFortune = new SubmitNewFortune(
$request->request->get('content')
);
$this->submitNewFortuneHandler->handle($submitNewFortune);
return new Response('', 201);
}
} |
As Symfony generally does not enforce certain techniques or conventions, is it worth mentioning that REST is not the only way to build APIs. Perhaps a note about how to choose whether REST is the right choice when starting a new build..? |
Does it worth to write a large documentation for building an API with Symfony? Or does we just need a smaller one that just explain some basic things and redirect users to Api Platform/FOSRestBundle? I would chose the 2nd option as Api Platform works out of the box and require less work than the simplest hand made REST API. |
Personally I'm not a fan of FOSRestBundle at all. So I would love to see ways of doing so without this bundle. |
@fbourigault I think we should build a little bit of documentation about what you will need to build an API, basic HTTP principle and maybe people don't want to use a Bundle and to build it alone. For those who talked about a symfony-demo app for building APIs, that's what ApiPlatform Standard Edition is doing. |
After years developing APIs REST with Symfony, from scratch, using the Form Component, then FOSRestBundle and now API Platform, I'd recommend to use API platform, but IMHO it has two "problems": hard learning curve for beginners and too much "Hydra centered" (Hydra is not suitable for all APIs, specially private ones used for M2M communication) Anyway, the documentation should have the following topics:
|
I propose to close this issues because in all these years, nobody took the lead to contribute these docs. The good news is that things have changed a lot during this time. We now have ApiPlatform as a great project to create APIs in Symfony apps. The documentation of that project is the way to fix this issue. Thanks! |
We currently completely ignore this topic, while it is a quite populair topic these days. #4022 started discussing this, but it didn't have a lot of progress.
The text was updated successfully, but these errors were encountered: