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

今天就学习课程吧!

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

Understanding HTTP request methods

Understanding HTTP request methods

- We're ready to send this proposed new name data to the server and persist it in MongoDB. We'll need to add a new endpoint to our API. We'll need to add it for both the router and the client. Let's start with the router. So we have "get" slash contests to give us a list of contests. We have "get" slash contest slash contest ID to give us the information for a single contest. And what we need now is another endpoint but this time we'll have to use either "post" or "put" not "get". We usually use "post" for creating a new entity in the database and we use "put" for updating an entity in the database. The one that we're doing here is a bit of both because we're really creating a new name but it's also updating the contest because our MongoDB structure is a single contest with nested documents. So I'll use "post." It doesn't matter if you use "post" or "put" they're kind of similar but you definitely cannot use "get"…

内容