Playing with APIs

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 361:- Playing with APIs

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)

Comments: 2

profile
@niteshguptav63
17-Nov-2024, 01:39 PM

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

profile
@niteshguptav63
16-Nov-2024, 10:56 AM

When will I get my course?

profile
@admin79
17-Nov-2024, 01:29 PM

Now, Your query was resolved.

Frequently Asked Questions (FAQs)

How do I register on Sciaku.com?
How can I enroll in a course on Sciaku.com?
Are there free courses available on Sciaku.com?
How do I purchase a paid course on Sciaku.com?
What payment methods are accepted on Sciaku.com?
How will I access the course content after purchasing a course?
How long do I have access to a purchased course on Sciaku.com?
How do I contact the admin for assistance or support?
Can I get a refund for a course I've purchased?
How does the admin grant access to a course after payment?