课程: Learning Full-Stack JavaScript Development: MongoDB, Node, and React

今天就学习课程吧!

今天就开通帐号,24,700 门业界名师课程任您挑!

Using an API endpoint from the browser

Using an API endpoint from the browser

- [Instructor] We created an API endpoint with Mock Data for the list of contests. Let's now figure out how to use it from the client. The first thing we need is a configuration variable. The reason we need a new configuration variable here is because I will not assume that the API server is the same as the host server. So introducing another server URL environment variable here is a good idea so that we get the option of running the API server on a different node. Let me name this one API server URL. And it's the same for our simplified project but we can add slash API here to simplify our calls. And then in the app component we need to load this data somewhere through an HTTP call. We can do it in the app component or we can do it in the main file where we tell React do to render an app component. Let me do it here. So we need an HTTP client A client capable of doing an HTTP request to a server and giving us back data.…

内容