Last Sync: 2022-08-04 15:00:04
This commit is contained in:
		
							parent
							
								
									b578ce659a
								
							
						
					
					
						commit
						7633dd971a
					
				
					 2 changed files with 25 additions and 1 deletions
				
			
		| 
						 | 
					@ -48,5 +48,5 @@ updateCourse({ name: "A new course" });
 | 
				
			||||||
Returns:
 | 
					Returns:
 | 
				
			||||||
 | 
					
 | 
				
			||||||
```js
 | 
					```js
 | 
				
			||||||
{ id: 1, name: { name: 'A new course' } }
 | 
					{ id: 1, name: 'A new course' }
 | 
				
			||||||
```
 | 
					```
 | 
				
			||||||
							
								
								
									
										24
									
								
								Programming_Languages/NodeJS/REST_APIs/4_DELETE.md
									
										
									
									
									
										Normal file
									
								
							
							
						
						
									
										24
									
								
								Programming_Languages/NodeJS/REST_APIs/4_DELETE.md
									
										
									
									
									
										Normal file
									
								
							| 
						 | 
					@ -0,0 +1,24 @@
 | 
				
			||||||
 | 
					---
 | 
				
			||||||
 | 
					tags:
 | 
				
			||||||
 | 
					  - Programming_Languages
 | 
				
			||||||
 | 
					  - backend
 | 
				
			||||||
 | 
					  - node-js
 | 
				
			||||||
 | 
					  - express
 | 
				
			||||||
 | 
					  - REST
 | 
				
			||||||
 | 
					  - apis
 | 
				
			||||||
 | 
					---
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					# Creating a REST API with Node and Express: DELETE requests
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					```js
 | 
				
			||||||
 | 
					app.delete("/api/course/:id", (req, res) => {
 | 
				
			||||||
 | 
					  const course = courses.find((c) => c.id === parseInt(req.params.id));
 | 
				
			||||||
 | 
					  if (!course)
 | 
				
			||||||
 | 
					    return res.status(404).send("A course with the given ID was not found");
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					  courses.indexOf(course);
 | 
				
			||||||
 | 
					  courses.splice(index, 1);
 | 
				
			||||||
 | 
					  res.send(course);
 | 
				
			||||||
 | 
					});
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					```
 | 
				
			||||||
		Loading…
	
	Add table
		
		Reference in a new issue