Coder Social home page Coder Social logo

backend-notes's Introduction

Backend is consist of HTTP Server, Authentication, Databases, Middlewares

  1. HTTP Server

HTTP Server is Consist of (a) Request Methods (b) URL port Route (c) Query Parameters, Headers, Body (d) Status Code (f) Response HTML, JSON Text (g) CORS

To contact with a server we need URL which is overall a IP address.

URL + Route = this is the most important thing when you are contacting with backend server. https://url.com/routes

Example : https://chat.openai.com/backend-api/conversation

  1. Query Params, Headers, Body are some ways to send the data to backend.

    Query params -> Example https://example.com/addition?counter=10000 ("?counter=10000" this is a parameter) -> So this is a way to send data to backend through URL

    -> In last example their was just singly query, but if we want send more queries then simply we can just use "&" . Example : https://example.com/addition?counter=10000&temp=1001&temp2=101 (here we have added 3 parameters)

    -> Now we know how to take input through query params but we have do some changes in backend to get this input.

    -> So get the query parameters in backend so that server can do some operatins on input we can write like "let counter = req.query.counter;"

IMP -> Every HTTP request have these things -> URL, Route, Method

Methods -> GET, POST, PUT, DELETE

IMP - In the URL bar browsers doesn't allow anyone to hit post request.

Headers -> Through Headers we can also send data to server from front end

Middlewares : Middlewares are most imp. They are the middleman between the routes and client. so actually what happen is when the request is made by user then that request is parsed from middlewares. So basically it is mostly use for authenticate the "request". Like the request which is coming from client side is authenticated request or not.

So the middleware has the power to pass the request to the respective route or it can reject the request too , next() without this request will be rejected by the middlewares.

-> way to register your middleware is pass it to app.use(middlewareFunction);

Body -> This is also the way to send data to backend -> 95% of time you will send data through body, so this is the most preferrable way to send data to backend. -> To extract info we cannot directly access through req.body.something -> we need to use body-parser so to install that just use this : npm i body-parser -> what app.use(bodyParser or anything) do? basically it makes the request come through this and make it in flow

Status Code : Http response status codes indicate whether a specific HTTP request has been successfully completed.

 -> Informational response : 100-199
 -> Successful respone : 200 - 299
 -> Redirection messages : 300 - 399
 -> Client error response: 400-499
 -> Server error response : 500 - 599

Response Body -> Their are three ways to send response

     1. Html
     2. json
     3. Simple text or string

backend-notes's People

Contributors

nitin1chandani avatar

Watchers

 avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.