-
Notifications
You must be signed in to change notification settings - Fork 63
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
POST methods broken #165
Comments
Hi @thomassdk, Thanks for reporting this; I tried replicating this problem on postman but can't. the post requests seem to be working just fine. |
The context I am trying to use the api in is the browser where the var raw = '{\n "country": "nigeria"\n}';
var requestOptions = {
method: "POST",
body: raw,
redirect: "follow",
};
fetch("https://countriesnow.space/api/v0.1/countries/states", requestOptions)
.then((response) => response.text())
.then((result) => console.log(result))
.catch((error) => console.log("error", error)); Which gives me the following error ❯ bun api.js
{"error":true,"msg":"missing param (country or iso2)"} Adding the query parameter returns the correct result var raw = '{\n "country": "nigeria"\n}';
var requestOptions = {
method: "GET",
};
fetch(
'https://countriesnow.space/api/v0.1/countries/states?country="Nigeria"',
requestOptions,
)
.then((response) => response.text())
.then((result) => console.log(result))
.catch((error) => console.log("error", error)); Confused as to why postman is working correctly... |
Would you like to update the documentation with the GET equivalent in the interim while we figure out what's wrong with the POST requests? |
@ink-pot-monkey feel free to open an MR for this fix 🤗 |
First let me say thanks for this great API.
I've noticed while playing around with it that all the POST methods seem to be broken i.e.:
I've got these requests to work with the query string, IE
❯ curl --location 'https://countriesnow.space/api/v0.1/countries/states/?country="Nigeria"'
So I am guessing something is going wrong with the Middleware redirection in
countriesNowAPI/middlewares/redirectPostToGet.js
Line 2 in 56c82cc
Is there anyway of investigating this further? I've cloned the repo and the tests pass, which contradicts my lived experience.
Alternatively, is it time to remove all the POST requests (at least in the documentation) for their proper GET versions? I'm happy to take this on
The text was updated successfully, but these errors were encountered: