Rendering an API

Dear Sciaku Learner you are not logged in or not enrolled in this course.

Please Click on login or enroll now button.

If you have any query feel free to chat us!

Happy Coding! Happy Learning!

Lecture 360:- Rendering an API

To render an API, you need to create a route that will respond to HTTP requests with data in a particular format such as JSON. Here's an example of how you can render an API using Node.js and Express:

javascriptCopy code

const express = require('express'); const app = express(); const products = [  { id: 1, name: 'Product 1', price: 10 },  { id: 2, name: 'Product 2', price: 20 },  { id: 3, name: 'Product 3', price: 30 } ]; app.get('/api/products', (req, res) => {  res.json(products); }); const port = process.env.PORT || 3000; app.listen(port, () => {  console.log(`Listening on port ${port}...`); });

In the example above, we have created an Express app and defined an array of products. We then created a route to handle GET requests to the URL /api/products. When a GET request is made to this URL, the server responds with the products array in JSON format using the res.json() method.

To test this API, you can use a tool like Postman to make a GET request to http://localhost:3000/api/products, which will return the array of products in JSON format.

42. APIs (Making APIs And JWT Authentication)

2 Comments

@niteshguptav63
niteshguptav63 Nov 17, 2024 at 1:39 PM

I am not able to access videos from second class and further. I have already completed first class

@niteshguptav63
niteshguptav63 Nov 16, 2024 at 10:56 AM

When will I get my course?

@admin79
admin79 Nov 17, 2024 at 1:29 PM

Now, Your query was resolved.

Frequently Asked Questions About Sciaku Courses & Services

Quick answers to common questions about our courses, quizzes, and learning platform

Didn't find what you're looking for?

help_center Contact Support