R
R
rrxrrx2016-08-15 09:52:56
PHP
rrxrrx, 2016-08-15 09:52:56

How to correctly render site templates when using the REST API?

Ask for help from community members.
I plan to develop an information site. Mostly textual information, pictures. Editorial + User generated content. Plus, over time, the site will be "hung" with various services - mainly directories, reference books, a forum, etc.
I do not consider any ready-made engine, although I have considerable experience working with many products - from WP to Bitrix.
Initially, I planned to write everything based on the mv-framework, since I implemented the latest projects on it. However, these were corporate sites, but here we are still talking about a service that will potentially be quite visited. Plus, it is already clear now that there will be a mobile application.
After reading a lot of articles about how to and how not to, the following picture more or less formed in my head:
It is best to immediately write an API on the principle of REST on some PHP framework. Most likely Slim or Silex. This is to make it easier to write the same mobile application later, and because of USG, many functions will overlap with the admin panel. I want to put the API somewhere on a subdomain, for example api.domain.ru, and send all requests from the backend and frontend there. And here questions arise:
1) How to implement authorization more correctly so that the API accepts requests only from the site and the application.
2) What is the best way to transfer files according to the REST API model? For example, uploading pictures to the gallery from the admin panel.
3) How to correctly render the site template? Throwing out JSON and processing handlebarsjs with some kind of not-so-good option from an SEO point of view (a content project). Or render the whole template on the server? Then how to give it within the framework of the REST API concept correctly? Or render a part on the server (which is critical for SEO), and load the data with AJAX via the API and parse JSON on the browser side, changing the DOM of the page where necessary? Again, I would like to make the same all the construction of the page (rendering) progressive. Or with the server side approach, it turns out only imaginary to do this with CSS?
And I also ask you to help me completely put in my head the general principle of backend / frontend interaction with data. We write a separate routing on the framework that implements REST and all the logic. And a separate routing that, when opened, communicates with the API?
For example, we have /register/ with a user registration form. We send data POST /user to api.domain.ru. We get the response in JSON and somehow output it to the browser, rendering either on the server or on the client? Or does the circuit work differently?
Thanks in advance for your detailed response and your time.

Answer the question

In order to leave comments, you need to log in

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question