A
A
Alexey Sklyarov2018-08-24 09:03:27
PHP
Alexey Sklyarov, 2018-08-24 09:03:27

How to move the methods and classes of the project into a separate API?

There is a project that is written on the skeleton: https://github.com/daveh/php-mvc . I will briefly describe the work:
There is a database with data, in my case data on currencies, the user data and their settings (for example, notification settings) are stored in the same database.
When loading the page, the user sends AJAX requests (about 3-4), receives data from the site (all requests go to an address like: /get/currency/price) and charts, bars, etc. are drawn based on the received data.
This logic of work is used on pages with currencies, in addition to these pages, there is an account page (which is immediately rendered by the server and given to the client) and static pages (also rendered by the server).

I had a desire to come to some order in the project, so I want to move most of the methods for working with currencies to a separate API, to which the client will send requests. But since there is only one database (it contains currency data, user data, etc., as mentioned above), the following questions arose:

  1. Is it bad practice to organize api work and site work with the same base? Or is it better to transfer data on currencies to a separate database and work with it only through api, and user data, etc. - to the database with which the site itself works?
  2. If in the future you need to take data on currencies when rendering a page by the server, what should you do? Receive data from api or copy a method from api to the site core in order to receive data immediately (perhaps the logic of work and the load will be identical in this case, but this is a flaw in the theory), is it in the case of using the same database for api and the site?
  3. What would you advise to read in order to understand this issue (and issues in this area) in more depth, most likely these are questions from the field of design, because I teach all this myself and there is a lack of theoretical knowledge?

Answer the question

In order to leave comments, you need to log in

2 answer(s)
I
Ivan, 2018-08-24
@0example

Is it bad practice to organize api work and site work with the same base? Or is it better to transfer data on currencies to a separate database and work with it only through api, and user data, etc. - to the database with which the site itself works?

It makes no sense to separate the database, and why? This is relevant only for microservices.
There are a lot of solutions, but the simplest one is to make universal MVC modules and counterpollers that would support both API feedback and just rendering.
About MVC and HMVC in particular.
Well, the implementation on examples, for example Laravel.

D
dmitriy, 2018-08-24
@dmitriylanets

I recommend looking in the direction of fractals from the league fractal league and implementing a data transport layer. To work on the server side repositories with objects and collections.

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question