简体   繁体   English

如何在 React 应用程序中使用 fetch 从 AWS RDS 获取数据?

[英]How to use fetch to fetch data from AWS RDS in a react application?

I'm learning Node + React.我正在学习 Node + React。 In my Node + React application, I have the following component FetchData.js to fetch data from localhost :在我的 Node + React 应用程序中,我有以下组件FetchData.jslocalhost获取数据:

import React from 'react';

class FetchData extends React.Component {

    static async getData() {
        let response = await fetch('http://localhost:4000/my-project');
        let body = await response.json();
        return body
    }
}

export default FetchData;

I could see the json objects by typing localhost:4000 in the browser.我可以通过在浏览器中键入localhost:4000来查看 json 对象。

Now I'm hosting the data in AWS RDS.现在我在 AWS RDS 中托管数据。 I have an endpoint like this:我有一个这样的端点:

my-project.abc12345def.eu-west-2.rds.amazonaws.com:3306

How can I fetch data from the endpoint like what I did in FetchData.js ?如何像我在FetchData.js中所做的那样从端点获取数据? I tried to replace localhost with the endpoint url, no luck;我尝试用端点 url 替换localhost ,但没有成功; tried to type the endpoint url in a browser, could not see its content.试图在浏览器中键入端点 url,但看不到其内容。 I suppose I need to be able to see its content to be able to fetch data?我想我需要能够看到它的内容才能获取数据?

I will give you most simple difference我会给你最简单的区别

Fetch is a way to access HTTP resources like http://localhost:4000/my-project . Fetch 是一种访问 HTTP 资源的方法,例如http://localhost:4000/my-project

Your RDS endpoint (Most probably MYSQL) does not run an HTTP server.您的 RDS 端点(很可能是 MYSQL)不运行 HTTP 服务器。

So these endpoints (Links) are different, and they are not for the same purpose.所以这些端点(链接)是不同的,它们不是为了同一个目的。

Edit: You could connect to RDS using a MYSQL client from your server running on http://localhost:4000 which then return the data to fetch request.编辑:您可以使用 MYSQL 客户端从运行在http://localhost:4000上的服务器连接到 RDS,然后返回数据以获取请求。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 React Native 如何从 Firebase Firestore 获取数组数据? - React Native how to fetch Array data from Firebase Firestore? 如何在 React Native 应用程序中从 Firebase 实时数据库中获取数据 - How to Fetch Data from Firebase Realtime Database in React Native App 如何在 React JS 中从 firebase 实时数据库中获取数据 - How fetch data from firebase realtime database in react js 在 React 项目中,ApolloProvider useQuery 组合不从 AWS AppSync 获取数据 - ApolloProvider useQuery combination does not fetch data from AWS AppSync, in React project React redux + 从 Firebase 获取数据 - React redux + fetch data from Firebase AWS rds - 如何从 Java 应用程序内部的只读副本读取? - AWS rds - How to read from a read replica inside of a Java application? 如何使用 NextJs 在 getServerSideProps 中从 Firebase 获取数据 - How to fetch data from Firebase in getServerSideProps with NextJs 如何从 firebase 获取数据并更新 - How to fetch data and update it from firebase 如何从 firebase 获取嵌套的 json 数据? - How to fetch nested json data from firebase? 如何从 flutter 中的云 firestore 获取数据? - How to fetch data from cloud firestore in flutter?
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM