Writing a Symfony2 cookbook entry about building REST API

502 views
Skip to first unread message

dalex...@jolicode.com

unread,
Jul 10, 2014, 3:58:59 AM7/10/14
to resting-wi...@googlegroups.com
The Symfony2 cookbook already contains a SOAP Webservice entry [1],
and I think we should try to make one for REST.

Their is plenty of way to do it, with the Bundles, or manually,
but a cookbook entry would have to keep it short and easy.

IMO we should explain the basics of doing it without the RestBundle:

- constrain the HTTP method;
- make your API stateless;
- using the Serializer from JMS;
- using a content negotiation library;
- accept PUT and POST to edit Doctrine2 entities;
- maybe talk a bit about authentication...

A second entry could talk about building it with all the power from RestBundle, Hateoas, ApiDoc...

By the way, resource editing is always tricky because we do not know what to do:
- accept a real XML/Json payload and use Serializer->deserialize to get an entity back?
- accept "application/x-www-form-urlencoded" and use a FormType to apply changes?

Applying changes on an entity from a real payload is a pain or is it just me? :)

Cheer,
Damien

William Durand

unread,
Jul 10, 2014, 4:11:01 AM7/10/14
to dalex...@jolicode.com, resting-with-symfony
A second entry could talk about building it with all the power from RestBundle, Hateoas, ApiDoc...

Well, I am probably biased but there are a few blog posts on this topic. None of them are "Symfony cookbook entries" though ;-)

Anyway, writing a recipe explaining the basics is a good idea!

By the way, resource editing is always tricky because we do not know what to do:
- accept a real XML/Json payload and use Serializer->deserialize to get an entity back?
> - accept "application/x-www-form-urlencoded" and use a FormType to apply changes?

There is a third scenario: you can accept a real xml/json payload, deserialize it "into" the request, and use a FormType. This one is my favourite. This particular topic definitely needs its own recipe ;-)

William


--
You received this message because you are subscribed to the Google Groups "RESTing with Symfony" group.
To unsubscribe from this group and stop receiving emails from it, send an email to resting-with-sym...@googlegroups.com.
To post to this group, send email to resting-wi...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/resting-with-symfony/bb49a2ba-b812-4465-bfff-d1de7f436d53%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

Swop

unread,
Jul 10, 2014, 2:37:03 PM7/10/14
to William Durand, Damien Alexandre, resting-with-symfony
The combination of the RestBundle BodyListener https://github.com/FriendsOfSymfony/FOSRestBundle/blob/master/EventListener/BodyListener.php and the JsonToFormDecoder https://github.com/FriendsOfSymfony/FOSRestBundle/blob/master/Decoder/JsonToFormDecoder.php is always a win for me :-)

Post a Json payload, treat the request as a x-www-form-urlencoded form POST in the controllers.

(you can even use a dynamic FormType to adapt the FormType fields depending on the sent fields for a PATCH request).

Swop


YoruNoHikage

unread,
Jul 11, 2014, 3:39:26 AM7/11/14
to resting-wi...@googlegroups.com
You're right. I'm a Symfony beginner and the blog posts I read explained how to do one thing but when you want to make a little change, it's pretty difficult...
I think knowing the wheel is very important not to reinvent it.

William Durand

unread,
Jul 11, 2014, 3:52:35 AM7/11/14
to YoruNoHikage, resting-with-symfony
Ok, so who's up for starting a pull request on https://github.com/symfony/symfony-docs?

William


--
You received this message because you are subscribed to the Google Groups "RESTing with Symfony" group.
To unsubscribe from this group and stop receiving emails from it, send an email to resting-with-sym...@googlegroups.com.
To post to this group, send email to resting-wi...@googlegroups.com.

dalex...@jolicode.com

unread,
Jul 14, 2014, 12:28:00 PM7/14/14
to resting-wi...@googlegroups.com, yoruno...@gmail.com
Yep,
I do not have a lot of time in front of me this month but I will try hard :)


Feel free to ping me for write access,
as I will not be able to write it entirely myself.

Damien.

William


To unsubscribe from this group and stop receiving emails from it, send an email to resting-with-symfony+unsub...@googlegroups.com.

To post to this group, send email to resting-wi...@googlegroups.com.

Di majo

unread,
May 8, 2024, 12:28:48 PMMay 8
to RESTing with Symfony
MT103/202 DIRECT WIRE TRANSFER
PAYPAL TRANSFER
CASHAPP TRANSFER
ZELLE TRANSFER
LOAN DEAL
TRANSFER WISE
WESTERN UNION TRANSFER
BITCOIN FLASHING
BANK ACCOUNT LOADING/FLASHING
IBAN TO IBAN TRANSFER
MONEYGRAM TRANSFER
IPIP/DTC
SLBC PROVIDER
CREDIT CARD TOP UP
DUMPS/ PINS
SEPA TRANSFER
WIRE TRANSFER
BITCOIN TOP UP
GLOBALPAY INC US
SKRILL USA
UNIONPAY RECEIVER

Thanks.


NOTE; ONLY SERIOUS / RELIABLE RECEIVERS CAN CONTACT.

DM ME ON WHATSAPP
+44 7529 555638
Reply all
Reply to author
Forward
0 new messages