Dev

Python

Flask service

from flask import Flask, request

app = Flask(__name__)

@app.route('/', methods=['POST'])
def webhook():
    try:
		    # Access data sended by POST
        data = request.json
    except Exception as e:
        # Exception catched
    return '', 200

if __name__ == '__main__':
		# Run app
    app.run(host='0.0.0.0', port=5001)

JS

Node server

  • req (request): Represents the HTTP request object, containing data such as headers, query parameters, and request body.

  • res (response): Represents the HTTP response object, used to send data back to the client.

1. Expecting GET Data (Query Parameters & URL Params)

a) Query Parameters (req.query)

  • Query parameters are sent in the URL after a ? and separated by &.

  • Example URL:

  • Access query parameters using req.query:

  • Use case: Searching, filtering, pagination, etc.

b) Route Parameters (req.params)

  • Route parameters are part of the URL path (e.g., /user/:id).

  • Example URL:

  • Access route parameters using req.params:

  • Use case: Fetching details of a specific item or user.

2. Expecting POST Data (Body Data)

For POST, PUT, PATCH requests, the data is usually sent in the request body.

a) JSON Data (req.body)

  • Ensure Express can parse JSON by using the express.json() middleware.

  • Example request body (JSON):

  • Express route to handle it:

  • Use case: Login, submitting forms, creating records.

b) Form Data (application/x-www-form-urlencoded)

  • If the form sends data as application/x-www-form-urlencoded (default for HTML forms), use:

  • Example HTML form:

  • Express route:

Last updated