Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
HTTP data fetching steps and terms

[11:45 PM] someuser : how can I pull data from mysql database using react js?
[11:46 PM] BTM : @someuser short answer - "you can't"
[11:46 PM] connor : have react hit a proxied api that makes request using mysql
[11:46 PM] connor : using fetch or axios
[11:46 PM] someuser : the package has apollo in it
[11:46 PM] BTM : You need an API that will expose the data from sql as REST, graphql etc.
[11:46 PM] someuser : whats the apollo for?
[11:46 PM] someuser : im confused between graphql, apollo and redux.
[11:46 PM] acemarke : okay, let me explain
[11:47 PM] acemarke : first: no matter what UI framework you're using, here's the basic data flow
[11:47 PM] acemarke : 1) JS code makes an HTTP AJAX request to an application server
[11:48 PM] acemarke : 2) The application server parses out any parameters, and makes a database query to retrieve some data
[11:48 PM] acemarke : 3) it formats the data from the DB and returns it to the client
[11:48 PM] acemarke : 4) the client takes the returned data and does something useful with it
[11:49 PM] someuser : got it
[11:49 PM] acemarke : these basic steps are true no matter whether you're using React, Angular, Vue, or jQuery for the UI; no matter whether you're using Node+Express, Python+Django, Java+Dropwizard, or something else for the server; and whether you're transmitting the data as XML, JSON, GraphQL, or anything else
[11:50 PM] acemarke : Now, how the HTTP request is formatted, what the server URL structure is like, and how the response is formatted, is up to you
[11:50 PM] acemarke : this is where terms like "REST", "RPC", "JSON-API", and "GraphQL" come in
[11:51 PM] acemarke : basically all different approaches to defining how requests, URLs, and responses are formatted
[11:52 PM] acemarke : @someuser : so, if you want to retrieve data from a MySQL database, you need a web application server process that can accept HTTP requests, figure out what the client is asking for, query the DB, and return an HTTP response

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment