Start a project in Symfony2 with APIRest

0

I'm new to symfony2 and I have a whole project already in web working that I developed to learn and have a differential when looking for an internship, but now I would like to start learning how to use the part of the API understood by the reference guide , how the drivers and routes work, and another question I asked, they pointed me to google's Postman, to test the things that it was developing. I looked for some tutorials and the majority was tar in English of Indians, which complicates because I am not fluent in English, I did not find anything that explained to me step by step how to begin.

Does anyone have any material to pass me?

    
asked by anonymous 11.12.2015 / 14:39

1 answer

1

Developing an REST API in Symfony2 does not differ much (in terms of code organization) from the development of a web system, for example. Some paradigms such as authentication and request / response type, however, are different.

The main libraries I use to develop REST APIs are:

Depending on the needs of your application, I also recommend these libraries:

As I said, what mainly changes is the authentication scheme and how data will be read and written (in JSON or XML, and with the use of HTTP verbs such as GET , PUT , POST and DELETE ).

By FOSRestBundle documentation, you learn how to configure your drivers to send serialized objects according to the client's request. You can send a single object, a collection of objects, enveloped or not - it's your choice. In addition, by JMSSerializerBundle , you can fine-tune which attributes of each object will be serialized on each route. For example, in a user list you can only pass the id and username of each, but at the time of picking up this user you can return all your attributes.

As for authentication, you obviously will not have a login form and password in order to provide access to that user's protected resources. Usually a basic authorization is used (in which credentials are passed by the Authorization header of the request using type Basic ).

However, this type of authorization exposes the credentials of the client in all requests, and you can opt for a slightly more structured authentication scheme - using OAuth v2 or another authentication protocol. In this protocol you only pass the credentials on the first call, and use access keys (which expire from time to time) for the following calls. The FOSOAuthServerBundle library helps you set up an OAuth client, as well as create the tables and provide an easy way to connect this type of authentication to your application routes.

Anyway, this is the way I work with APIs in REST. If you have any further questions or need help in implementing any of the libraries I mentioned above, just talk. :)

    
17.12.2015 / 13:15