Home > Net >  how to send "messagebody" directly in api call to SQS queue via url without using postman?
how to send "messagebody" directly in api call to SQS queue via url without using postman?

Time:12-28

i have api gateway with 3 simple backends:

  • 2 basic api routes (/plus and /minus) backed by lambda functions
  • 1 direct sqs queue (/sqs_send)

It means i can send via api call directly to my sqs queue.

2 lambda backend functions take 2 params 'a,b' from api call and add,subtract and show output.

https://86bwtlv5ya.execute-api.us-east-1.amazonaws.com/minus?a=10&b=20 # prints -10 in browser

https://86bwtlv5ya.execute-api.us-east-1.amazonaws.com/plus?a=10&b=20 # prints 30 in browser

The 3rd function is tricky for me. Via postman i managed to send directly to sqs like this via put request. Notice how i have to select "body" "raw" then input message. I did check the sqs queue - the msg from postman is there.

kk

My question - what to type into my api gateway endpoint to send msg directly to sqs? Without using postman?

https://86bwtlv5ya.execute-api.us-east-1.amazonaws.com/sqs_send?mesagebody # what to type after sqs_send?

This did not work - returns {"message":"Not Found"}

https://86bwtlv5ya.execute-api.us-east-1.amazonaws.com/sqs_send? 
 Action=SendMessage&
 MessageBody=This is a test message

Is it possible, my sqs_send api route does not work with parameters, because it is designed to only work with "messagebody" as per my settings? "Message attributes" is empty?

kk898

CodePudding user response:

If I understood correctly, you want to call your API gateway endpoints by directly entering the URL into your browser's address bar.

Short answer: Unfortunately you can't do this with your 3rd endpoint /sqs_send, because it is a PUT endpoint which the browser cannot call directly through the address bar.

Details: Browsers usually support only HTTP GET and POST methods directly, through form submissions (which in turn is an HTML limitation, where form submissions only support these two methods). In GET method, parameters are appended to the end of the URL in the pattern example.com/?name1=value1&name2=value2. In POST method, parameters are included in the body of the request, so they're not visible in the URL itself. This means that you can only call GET endpoints by directly typing into the address bar of your browser. Your /plus and /minus are likely GET endpoints. POST endpoints must be called via HTML form submissions to include your parameters.

For calling other methods like PUT and DELETE (in addition to GET and POST), you will have to use XMLHttpRequest or the Fetch API, or some frontend framework method built around them. As your Postman screenshot shows, your third endpoint /sqs_send is a PUT, so you can't call it directly by entering the URL into the browser's address bar. If you must call it this way, you will have to convert your endpoint to a GET so that you can send your parameters via URL parameters.

  • Related