Sushant Bajracharya
Sushant Bajracharya

Reputation: 63

Whether to use FOSRestBundle or just json_encode()?

I am creating an API with Symfony 2. I'm using FOSRestBundle for this. Since the bundle and json_encode() return the same result, why should I use the bundle?

Why shouldn't I use json_encode() to encode the array into JSON for returning the response?

Upvotes: 0

Views: 341

Answers (2)

Dipen Shah
Dipen Shah

Reputation: 1919

why should i use the bundle?

Well depends on what your requirements are. If you're trying to develop restful APIs or some fancy things like that you should definitely go with the bundle. If you're just trying to display some json data to the front end just go with a simple json_encode.

Upvotes: 1

Nickolaus
Nickolaus

Reputation: 4835

In my opinion the biggest advantage is that you don't need to take care of the data-structure using the bundle you will get valid json structures, furthermore it provides functionality to configure the request your are sending (header data, etc)

So if you are working with more than one or two simple request it might be easier using the bundle, however you will need some time in the beginning for a suitable setup

Upvotes: 0

Related Questions