Routes: Difference between revisions

no edit summary
No edit summary
No edit summary
 
Line 3: Line 3:
Routes are the things that define how URLs get mapped to program logic, and masto defines them in a bunch of places.
Routes are the things that define how URLs get mapped to program logic, and masto defines them in a bunch of places.


Oddly this is one of the few things that mastodon has developer documentation for: https://docs.joinmastodon.org/dev/routes/
Oddly this is one of the few things that mastodon has developer documentation for<ref>Masto Docs: Routes - https://docs.joinmastodon.org/dev/routes/</ref>


== Rails ==
== Rails ==
Line 14: Line 14:
* API routes: <code>config/routes/api.rb</code> (and other routes in there too)
* API routes: <code>config/routes/api.rb</code> (and other routes in there too)


See the [https://guides.rubyonrails.org/routing.html Rails routing docs] for more on how they work.
See the Rails routing docs<ref>Rails Docs: Routing - https://guides.rubyonrails.org/routing.html </ref> for more on how they work.


The basic pattern for a route will look something like this:
The basic pattern for a route will look something like this:
Line 26: Line 26:
=== Views ===
=== Views ===


Rails then implicitly passes those parameters on to a "view," or an html template that is compiled and then returned to the browser. In this case the relationship to the view is also implicit, depending on file names, so the view that is invoked is <code>views/statuses/show.html.haml</code>.
Rails then implicitly passes those parameters on to a "view,"<ref>Rails Docs: Views - https://guides.rubyonrails.org/layouts_and_rendering.html</ref> or an html template that is compiled and then returned to the browser. In this case the relationship to the view is also implicit, depending on file names, so the view that is invoked is <code>views/statuses/show.html.haml</code>.


That page is mostly a stub, because most of the actual rendering of the page is done clientside with react/redux.
That page is mostly a stub, because most of the actual rendering of the page is done clientside with react/redux.
Line 36: Line 36:
* Main routes <code>app/javascript/flavours/glitch/features/ui/index.jsx</code>
* Main routes <code>app/javascript/flavours/glitch/features/ui/index.jsx</code>


The React routes map a given URL location to the page that is to be displayed. So while the rails routers will give a little bit of header information to the page, the rest of the page that is served is identical across most pages. The clientside React controls what is shown for a given page, rather than the serverside Rails.
The React routes map a given URL location to the page that is to be displayed.<ref>React Router Docs - https://reactrouter.com/en/main</ref> So while the rails routers will give a little bit of header information to the page, the rest of the page that is served is identical across most pages. The clientside React controls what is shown for a given page, rather than the serverside Rails.


So, for example, the statuses route looks like this:
So, for example, the statuses route looks like this:
Line 48: Line 48:
After that, the guide picks up at [[Redux]]
After that, the guide picks up at [[Redux]]


== References ==
<references />


[[Category:Mastodon]]
[[Category:Mastodon]]
[[Category:Docs]]
[[Category:Docs]]