Home > OS >  Can I send GET data via raw JSON with Postman?
Can I send GET data via raw JSON with Postman?

Time:08-13

If I using Post method like this :

enter image description here

It works. I success get data id from backend

If I using Get method like this :

enter image description here

I can't get json data. Json data is empty

My code in backend :

public async test({ request, response }: HttpContextContract) {
    return request.body()
}

Is it possible to use the GET method?

CodePudding user response:

Your backend is just returning whatever you send. So in the POST request you're actually SENDING "id": [1,2,3], which then gets sent back to you.

Typically GET requests do not send a BODY, they just access and endpoint. So your backend might not be looking for a body on the GET request, and is returning empty JSON.

You would usually have a separate backend function (or case statement) for POST and GET options. The POST case would parse the body, do an update, return a status, etc. The GET case might parse the URL (test/123), do a DB lookup based on the ID 123, and return the username and email.

There might be some good YouTube tutorials on building an API with the framework you're using, that would be a great place to start!

CodePudding user response:

You can pass a body with GET, but YMMV

I wouldn't recommend it, I recently went through this with a DELETE. It actually worked fine in Postman, but WebClient didnt support it.

You can either pass them as query parameters, or change your request to a POST, which may be more secure depending on the sensitivity of your ID's and implementation.

  • Related