Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Proper RESTful SOA approach in PHP applications?

So, i've been reading a lot on SOA's lately and been trying to implement something useful. I have started with a simple blog, creating the RESTful API. So far, so good. It works perfectly. However, i'm starting to pull my hair off when writing the web interface that will consume the RESTful API. I don't know if i'm doing the right thing.

For example, the web interface has an admin panel. That admin panel makes HTTP requests to the API, through file_get_contents and stream options. Right now, the API is localhost, as well the web interface, but the whole process is a little slower. Is this right? Is this the proper way of implementing a SOA? Also, i'm dealing with little bits of duplicated code for validation. Where should i validate data? In the API or the web interface? What is the best approach?

Tips, tutorials and, specially, books are welcome. This is being implemented using Silex, built on top of Symfony components.

like image 722
vinnylinux Avatar asked Nov 13 '22 01:11

vinnylinux


1 Answers

That's exactly how i do it. Although the connection with localhost might seem an overhead at first, it is a feature, since you're ready to deploy your web interface application anywhere and still consume your API, that might be anywhere. Of course, you would put some SSL over this.

As for Validation, you should validate on the API and return HTTP status codes for those situations (for example, "400 Bad Request" for invalid parameters). This way, any other client can interpret the response from the API and treat that to display how they want. In the case of your web interface, nice little error messages based on the HTTP status code.

What other problems are you facing? Also, as far as general SOA architecture is concerned, this book is very good.

like image 186
Klaus S. Avatar answered Dec 22 '22 06:12

Klaus S.