Skip to content

POST and GET on the same route #126

@samkpo

Description

@samkpo

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?

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions