Start a project on Symfony2 with Apirest

Asked

Viewed 113 times

0

I am new to symfony2 and I have a whole web project already working that I developed to learn and have a differential when it comes to 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 controllers and routes work, and by another question I asked, I was shown the Google Postman, to test the things I was developing. I searched some tutorials and out most tar in English from Indians, which complicates because I am not fluent in English, I did not find anything that would explain me step by step how to start.

Someone has some material to pass me?

1 answer

1


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

The main libraries I use to develop REST Apis are:

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

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

For the documentation of FOSRestBundle, You learn how to configure your controllers to send serialized objects according to the client’s request. You can send a single object, a collection of objects, enveloped or not - the choice is yours. Also, by JMSSerializerBundle, you can make a fine-tune in which attributes of each object will be serialized in each route. For example, in a user listing you can only pass the id and the username of each, but at the time of picking up this user you can return all its attributes.

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

However, this type of authorization exposes the client’s credentials in all requests, and you can opt for a slightly more robust authentication scheme - using Oauth v2 or another authentication protocol. In this protocol you only pass credentials on the first call, and use access keys (which expire from time to time) for subsequent calls. The library FOSOAuthServerBundle helps set up an Oauth client, in addition to creating the tables and providing 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 more questions or need help implementing any of the libraries I mentioned above, just say the word. :)

Browser other questions tagged

You are not signed in. Login or sign up in order to post.