I want to try to write an application on the server side of RoR Api on the front of React SPA. I do not understand how to correctly implement routing on the site. I myself would have done something like http://api.site.ru/ And the routers completely coincided with http://site.ru/ but I think that this is not quite true?

Closed due to the fact that it is necessary to reformulate the question so that you can give an objectively correct answer by the participants of D-side , cheops , aleksandr barakin , Grundy , VenZell 20 May '16 at 16:12 .

The question gives rise to endless debates and discussions based not on knowledge, but on opinions. To get an answer, rephrase your question so that it can be given an unambiguously correct answer, or delete the question altogether. If the question can be reformulated according to the rules set out in the certificate , edit it .

  • When it comes to SPA (Single Page Application) server URLs are usually tied to data and not to pages. Although much depends on the mechanism of client-server communication (REST, socket.io, GraphQL). - Dmitriy Simushev
  • REST. Where can you read about it? Now I implement it so that the api was in the API folder and the front end completely repeats the backend routes only the backend in the api folder - Pavel
  • If REST, then, obviously, in the literature on REST =) Although I want to warn you right away: React is only a View from MVC. To build a full-fledged client application, you should consider exactly how the data will fall into the React components. You can look at the fashionable ideology of flux / redux. - Dmitriy Simushev
  • It's all clear, it is exactly how to combine the routing) - Pavel
  • one
    Um ... SPA always has one entry point. And REST API routes can be anywhere. The option with an additional directory ( /api ) is an acceptable solution. - Dmitriy Simushev

1 answer 1

I never did it myself, but from those projects that I saw, it was just a duplication of the routes. Those. On the front, the necessary routes for api are clearly indicated in the configs. If the front is given by the same application as api - it is possible to automate - provide a view with routes. If it is different, you can try to make a method in the API for getting routes. But I don’t see any special charm in this - only an additional load on the backend.