Home > OS >  Can you use a POST to GET data?
Can you use a POST to GET data?

Time:02-12

A company is asking me to do an Angular assignment. They provide the following instructions, but the API URL doesn't work:

Create a single page angular application and use the following API to retrieve sports results and sort into a table of results that are displayed. Each sport result contains several data and always includes the publication time. 
Method: POST
Content-Type: application/json
Url: https://ancient-wood-1161.getsandbox.com:443/results 
Tasks:
-Display the sports results in reverse chronological order on the page.
-Add a filter to the page to display only certain types or events (e.g. f1Results)
-How can you confirm the code works?
-Bonus: Implement the rest call asynchronously

You can click the URL https://ancient-wood-1161.getsandbox.com:443/results right now and see that it doesn't work - it returns {"errors":[{"message":"Error processing request"}]} and in Angular it gives me a standard CORS error.

I asked the company to please send a working URL and/or update the API to accept requests from everywhere. Their response was: *guy's name* confirmed it worked. It is a post and the content type is json.

Am I crazy? Can you use a POST request to GET data? What data would I even need to POST in order to receive the data?

CodePudding user response:

Yes, you can. On some cases it may be necessary, since GET doesn't take a body while POST does. So it can get you around things like URL length limits.

CodePudding user response:

Absolutely. Take for example your avg Login Request that returns an access token for instance. It is going to be a POST as POST also has a bit more security than GET given that the payload is in the body rather than the URL string.

As for their excuse of it not working, try it in postman and see if the same issue still occurs. If it still does then ask them where did they test their API as if it is on prem then no duh the CORS would work. It is most likely not a company you would want to work for.

  • Related