Skip to main content

Params & Body

new data.json

{
  "users": [
    {
      "id": 1,
      "firstname": "Alice",
      "balance": 1000,
      "credit_ID": 2
    },
    {
      "id": 2,
      "firstname": "Bob",
      "balance": 500,
      "credit_ID": 1
    },
    {
      "id": 3,
      "firstname": "Charlie",
      "balance": 1500,
      "credit_ID": 4
    },
    {
      "id": 4,
      "firstname": "David",
      "balance": 2000,
      "credit_ID": 3
    }
  ],
  "banks": [
    {
      "id": 1,
      "owner": 1,
      "sender": "Alice",
      "receiver": 2,
      "note": "For lunch",
      "amount": 200,
      "bank": "Bank A",
      "type": "transfer"
    },
    {
      "id": 2,
      "owner": 2,
      "sender": "Bob",
      "receiver": 1,
      "note": "Repayment",
      "amount": 100,
      "bank": "Bank B",
      "type": "transfer"
    },
    {
      "id": 3,
      "owner": 3,
      "sender": "Charlie",
      "receiver": 4,
      "note": "Gift",
      "amount": 500,
      "bank": "Bank C",
      "type": "transfer"
    },
    {
      "id": 4,
      "owner": 1,
      "sender": "Alice",
      "receiver": 3,
      "note": "For lunch",
      "amount": 500,
      "bank": "Bank A",
      "type": "transfer"
    },
    {
      "id": 5,
      "owner": 1,
      "sender": "Alice",
      "receiver": null,
      "note": "Dispose for expenses",
      "amount": 300,
      "bank": "Bank A",
      "type": "dispose"
    },
    {
      "id": 6,
      "owner": 3,
      "sender": null,
      "receiver": "Charlie",
      "note": "Withdraw for emergency",
      "amount": 200,
      "bank": "Bank C",
      "type": "withdraw"
    },
    {
      "id": 7,
      "owner": 2,
      "sender": null,
      "receiver": "Bob",
      "note": "Withdraw for rent",
      "amount": 150,
      "bank": "Bank B",
      "type": "withdraw"
    },
    {
      "id": 8,
      "owner": 4,
      "sender": null,
      "receiver": "David",
      "note": "Dispose for savings",
      "amount": 1000,
      "bank": "Bank C",
      "type": "dispose"
    },
    {
      "id": 9,
      "owner": 4,
      "sender": null,
      "receiver": "David",
      "note": "Withdraw for investment",
      "amount": 700,
      "bank": "Bank C",
      "type": "withdraw"
    },
    {
      "id": 10,
      "owner": 2,
      "sender": null,
      "receiver": "Bob",
      "note": "Dispose for utilities",
      "amount": 80,
      "bank": "Bank B",
      "type": "dispose"
    }
  ]
}

}

In JavaScript, "Params"Params," "Query," and "Body" are terminologies commonly used in the context of HTTP requests. Theytypically refer to different parts of thean HTTP request thatwhen carrybuilding dataweb toapplications, theespecially server.

when

working with frameworks like Express.js in Node.js.

Params: Short for "parameters", theyThese are URL parameters passed in the URL itself. They are part of the URL path and typically used in the context of GET requests. Parameters are key-value pairs appended to the end ofidentify a URLspecific after a question mark (?).resource. For example, in the URL https://example.com/search?q=hellousers/:userId, q:userId is a parameter withthat can be accessed in the valueserver-side code.

Example:

image.png

Query: These are parameters passed in the URL query string. They come after the hello?. Parametersin a URL and are used for filtering or modifying the resource being requested.

Example:

image.png

 

Body: This is the data sent as part of the HTTP request body. It is used to send smallmore amountscomplex ofdata, datalike JSON objects, from the client to the server.server, Intypically webin development,POST frameworks,or andPUT librariesrequests.

often

To provideaccess convenientthe waysbody in Express.js, you typically need middleware like body-parser to parse and access these parameters.


 

  • Body: Thethe body of an HTTP request is the main part of the request where you can send a larger amount of data to the server. It is commonly used in POST, PUT, and PATCH requests. The body is separated from the headers (which contain metadata about the request) by a blank line. The body can contain various types of data, such as JSON, XML, or plain text, depending on the content type specified in the headers of the request. In webmore development,modern versions of Express.js, this functionality is integrated into Express itself.

    image.png

    Example:

    image.png

    To Testing send body using the server-sidepostman

    code
      parses
    1. open thepostman and click body
      of the request to extract the necessary information sent by the client.

      image.png

  • click raw

    image.png


  • select sending type JSON

    image.png


  • fill the Body

    image.png


  • send

    image.png

  • -- End of this example --