![]() ![]() However, the JavaScript ecosystem is constantly evolving. It is a great choice for building APIs, especially REST APIs. For example, the /products endpoint represents the collection of products stored in the database.įor a full tutorial on how to build a REST API with Express and MongoDB, see Building a REST API with Express, Node, and MongoDB.Įxpress is a robust solution that has been around for more than 10 years. The different resources exposed as endpoints from the API represent collections in the database. A common use case is to create a REST API that stores data in a database, such as MongoDB. You can build on top of this simple routing example to work with real data. Similarly, the app.put() method is used to handle a PUT request on the /products/:productId route, where :productId is a parameter that is extracted from the URL. For example, the app.get() method is used to handle a GET request on the /products route. The code above uses methods of the app object that correspond to HTTP methods-GET, POST, PUT, and DELETE. Return res.send('POST HTTP method on product resource') Īpp.put('/products/:productId', (req, res) => resource`) Īpp.listen(3000, () => console.log('Server is running on port 3000')) Return res.send('GET HTTP method on product resource') The following sample implements a REST-like API with Express in only 20 lines of code! const express = require('express') ![]() Express is often used for creating APIs, especially REST APIs. ![]() It is part of the OpenJS foundation and has an active community of contributors.Įxpress extends the Node.js http package with features for routing, middlewares, and views. Express is a free and open-source MIT-licensed project. It is designed to be fast, minimal, and modular. Express is a minimal web application framework for Node.js. ![]()
0 Comments
Leave a Reply. |