How to use GET method to access remote API using XMLHttpRequest with React client and Express server
井民全, Jing, mqjing@gmail.com
Github: viewYou can use XMLHttpRequest easily to send GET requests with parameters to the server. Here is an example, I used React as a client and Express as a server.
Fig. The system flow. (Edit)
Enjoy!
By Jing.
Quick
Client
Ex
Server
File: routes/xxxapi.ts
Table of contents
1. Client (React)
File: App.tsx (Partial code)
2. Server (Express)
File: routes/status-api.ts
File: index.ts
3. Install, Run, Test
3.1. Install
3.2. Run
3.3. Test
3.4. Make clean
3.4.1. Clean script: Server
File: ./server/package.json
3.4.2. Clean script: Client
File: ./client/package.json
4. References
Express 4.x - API Reference, http://expressjs.com/en/api.html#req.query
How To Use the req Object in Express, https://www.digitalocean.com/community/tutorials/nodejs-req-object-in-expressjs
XMLHttpRequest, https://javascript.info/xmlhttprequest
Using XMLHttpRequest, https://developer.mozilla.org/en-US/docs/Web/API/XMLHttpRequest/Using_XMLHttpRequest
5. Further Information
[react, express, deploy] How to deploy the React App with Express (view)
[react, express, restfulAPI] How to implement a restfulAPI using Express and React (view)
[react, express, sse] How to create server that streams events to the front-end client using Express and React**** (view), (blog)
[html, xhr, get] How to use GET method to access remote api using XMLHttpRequest with React client and Express server*** (view) <--- this document