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": "Deposit for expenses",
      "amount": 300,
      "bank": "Bank A",
      "type": "deposit"
    },
    {
      "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": "Deposit for savings",
      "amount": 1000,
      "bank": "Bank C",
      "type": "deposit"
    },
    {
      "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": "Deposit for utilities",
      "amount": 80,
      "bank": "Bank B",
      "type": "deposit"
    }
  ]
}

In JavaScript, "Params," "Query," and "Body" typically refer to different parts of an HTTP request when building web applications, especially when working with frameworks like Express.js in Node.js.

image.png

image.png

Params: These are URL parameters passed in the URL itself. They are part of the URL path and typically used to identify a specific resource. For example, in the URL /users/:userId, :userId is a parameter that can be accessed in the server-side code.

Example:

image.png

Query: These are parameters passed in the URL query string. They come after the ? in 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 more complex data, like JSON objects, from the client to the server, typically in POST or PUT requests.

To access the body in Express.js, you typically need middleware like body-parser to parse the body of the request. In more modern versions of Express.js, this functionality is integrated into Express itself.

image.png

Example:

image.png

To Testing send body using the postman

  1. open postman and click body

    image.png

  2. click raw

    image.png


  3. select sending type JSON

    image.png


  4. fill the Body

    image.png


  5. send

    image.png

-- End of this example --