Skip to content
New issue

Have a question about this project? # for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “#”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? # to your account

Use the base path provided in method "add_subapi" for an api path. #127

Open
wants to merge 1 commit into
base: master
Choose a base branch
from

Conversation

samkpo
Copy link

@samkpo samkpo commented Sep 17, 2023

If a subapi is created this will allow to define an endpoint like this very one if desired:

http_api subapi;
subapi.get("/") = [&](http_request& request, http_response& response) {
	response.write("hello");
};
subapi.get("/world") = [&](http_request &request, http_response &response) {
	response.write("hello world");
};

http_api my_api;
my_api.add_subapi("/hello", &subapi);

It allows us to definea method within the subapi route by the subapi itself.

If a subapi is created this will allow to define an endpoint like this very one if desired:

```c++
http_api subapi;
subapi.get("/") = [&](http_request& request, http_response& response) {
	response.write("hello");
};
subapi.get("/world") = [&](http_request &request, http_response &response) {
	response.write("hello world");
};

http_api my_api;
my_api.add_subapi("/hello", &subapi);
```
@cong1920
Copy link
Contributor

If a subapi is created this will allow to define an endpoint like this very one if desired:

http_api subapi;
subapi.get("/") = [&](http_request& request, http_response& response) {
	response.write("hello");
};
subapi.get("/world") = [&](http_request &request, http_response &response) {
	response.write("hello world");
};

http_api my_api;
my_api.add_subapi("/hello", &subapi);

It allows us to definea method within the subapi route by the subapi itself.

Thanks @samkpo! I think this your makes more sense as with your sample code above

BEFORE:

REQUEST / -> RESPONSE 404 not found
REQUEST /hello -> RESPONSE 404 not found
REQUEST /hello/ -> RESPONSE 404 not found
REQUEST /hello/world -> RESPONSE hello world

AFTER:

REQUEST / -> RESPONSE 404 not found
REQUEST /hello -> RESPONSE hello
REQUEST /hello/ -> RESPONSE hello
REQUEST /hello/world -> RESPONSE hello world

However the source code file your edited is auto generated from libraries/http_server/http_server/api.hh. You should make changes in that api.hh, generate this one and the lithium.hh, and add all three files in your PR.

cong1920 added a commit to cong1920/lithium that referenced this pull request Dec 30, 2024
...as the title says but in fact the code change is done by @samkpo in
PR matt-42#127. I am just adding test coverage, making change in the right file
with all files generated.
@cong1920
Copy link
Contributor

@samkpo hope you don't mind I just moved your change to the api.hh, added test coverage and regenerated all files in #131

cong1920 added a commit to cong1920/lithium that referenced this pull request Dec 30, 2024
...as the title says but in fact the code change is done by @samkpo in
PR matt-42#127. I am just adding test coverage, making change in the right file
with all files generated.

This PR also adds one missing header file to to sql_database.hh to fix
build breaks.
# for free to join this conversation on GitHub. Already have an account? # to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants