//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 = [Link]
>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. [Link]
>/api is not necessary . some companies follow this convention to expose
their restful services.
we can also use api as a subdomain also. like----- [Link]
> 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();
[Link]('/',(req,res) => {
[Link]('hello world >');
});
[Link]('/api/cources', (req,res) => {
[Link]([1, 2, 3]);
});
//port enviornment variable
const port = [Link] || 3000;
[Link](port, () => [Link](`listening on the port ${port}....`));