this post was submitted on 04 Jul 2023
1 points (100.0% liked)
ELI5
18 readers
1 users here now
Explain it to me like I am 5. Everybody should know what this is about.
founded 1 year ago
you are viewing a single comment's thread
view the rest of the comments
view the rest of the comments
@AvgCakeSlice hey there,
If I get you right this means, that React basically calls the back-end from the client when needed - so potential risk for injection?
And PHP or C# are doing it beforehand and send the stuff to the client?
No, not necessarily. React usually calls the backend through HTTP requests in order to fetch data. The backend code is written as an API, not a full-blown web application, that handles those requests, validates the request, permissions, business logic, etc, and then returns a response. The backend code is the gatekeeper between the client and any databases or external API’s in your application.
Traditionally you would use REST API’s, although there are more modern ways of communicating with a backend like with graphQL. But if you’re just starting I would learn how to write a REST API using PHP, Python, Ruby, C#, etc and go from there. REST API’s are pretty straightforward. Essentially your server just exposes a bunch of “endpoints” which are URL’s that represent a resource (for example
https://mycoolwebsite.io/api/users
) and making certain calls to those endpoints prompts the server to perform some action (for example, an HTTP GET request to api/users/123 gives you the information of the user with the ID ‘123’) the server typically serializes the response data to JSON, so that the client can then receive the response from the server and do something with it. When writing your backend, you are responsible for defining these endpoints in your code and writing the logic that executes whenever a given endpoint is called. For example, when creating a new user (with an HTTP POST request to api/users), you may want to send an email to the newly-created user for them to validate their email address. You would do this by calling some external email service like SendGrid, Mailchimp, etc. and sending a validation email to the address that the user sent in the request body. After that you would create a new user record in the database and initialize the “is_account_verified” field of that user to false. In another endpoint (api/users/{id}/verify-email) you would then check if the verification email has expired or not, then change the verified flag in the DB if it is a valid link.@AvgCakeSlice okay I understand. In your own mind. Would you rather code with "traditional" languages or react?
Well, both, but if you’re just talking about the frontend, then yeah I’d use a frontend framework like React (though personally I’d rather use Vue or Svelte if I had the choice)
@AvgCakeSlice What makes you choose Vue and Svelte over React? I only.know that React is hyped a lot and also on job listings.