0% found this document useful (0 votes)
11 views2 pages

Node

Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as TXT, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
11 views2 pages

Node

Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as TXT, PDF, TXT or read online on Scribd
You are on page 1/ 2

//what is API//

->
=>restful services=>
also known as restful APIs.

it is based on client server architechure.


>the communication between cliend and server happens using a http protocol request.
>server provieds the required bunch of services and client can access this services
though http request.
>rest is besically a convention to building these http services.
> a single http protocol provide services like create , read , update, delete data

eg: on server the end point looks like = http://vidya.com/api/courses


>client can send http req. to this endpoint to access the services.
> addess starts with http or https. when we want to send data in a secured
channel we use https
>next we have domain of the application i.e. vidya.com
>/api is not necessary . some companies follow this convention to expose
their restful services.
we can also use api as a subdomain also. like----- api.vidya.com
> then we have /courses that shows the colloecton of courses the app
have....also known as resources.

> a http request is made to make any changes in the courses end point.
>every http request is known as`method ` and that decides its intention.
>standard http methods are [GET POST PUT DELETE ]

>GET==
to receive the list of courses available in the app we use GET method.
if we write the idea or index of the course in the domain like
GET/api/courses/math OR GET/api/courses/05
then we can get the exact value of that index
syntax:-- GET/api/courses

>PUT==
to update a courses we have to send http put request to the endpoint.
also we have to enter the updated proporty of the object and send it to the server.
server will update the requirement values.
syntax:-- PUT/api/courses

>DELETE==
to delete a course we have to send http delete request to the server.
syntax:-- DELETE/api/courses/05

>POST==
send a http post request to create a course
have to enter the proporty of the new object and send it to the server. server
will create the requirement values.
syntax:-- DELETE/api/courses

const express = require('express');


const app = express();

app.get('/',(req,res) => {
res.send('hello world >');
});
app.get('/api/cources', (req,res) => {
res.send([1, 2, 3]);
});

//port enviornment variable

const port = process.env.PORT || 3000;

app.listen(port, () => console.log(`listening on the port ${port}....`));

You might also like