Skip to content
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 and GET on the same route #126

Open
samkpo opened this issue Sep 17, 2023 · 0 comments
Open

POST and GET on the same route #126

samkpo opened this issue Sep 17, 2023 · 0 comments

Comments

@samkpo
Copy link

samkpo commented Sep 17, 2023

I'm trying to create a REST api. I already had the GET method, but when I added the post method on the same route ("/") it disables the previous defined GET. Same goes if I first define the POST and then the GET method, only the last one define stays.

http_api my_api;

my_api.get("/") = [&](li::http_request& request, li::http_response& response) {
        throw li::http_error::unauthorized("You cannot access this route.");
};
my_api.post("/") = [&](li::http_request& request, li::http_response& response) {
        throw li::http_error::unauthorized("You cannot access this route.");
};
# this works
curl --header "Content-Type: application/json" \
  --request POST \
  --data '{ "age": 2}' \
localhost:3000
You cannot access this route.

# this does not
curl -vXGET localhost:3000
Method GET not implemented on route /

Is there any way to make this work?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant