babelouest / ulfius

Web Framework to build REST APIs, Webservices or any HTTP endpoint in C language. Can stream large amount of data, integrate JSON data with Jansson, and create websocket services
https://babelouest.github.io/ulfius
GNU Lesser General Public License v2.1
1.07k stars 183 forks source link

[Issue] simple example.c: Why All routes go to default endpoint #189

Closed BaseMax closed 3 years ago

BaseMax commented 3 years ago

Describe the issue

Why All routes go to default endpoint?

[max@base simple_example]$ ls
Makefile  README.md  simple_example  simple_example.c  simple_example.o
[max@base simple_example]$ ./simple_example 
2021-03-27T19:37:16Z - simple_example INFO: Starting simple_example
2021-03-27T19:37:16Z - simple_example DEBUG: Start framework on port 8537
^C
[max@base simple_example]$ make
make: Nothing to be done for 'all'.
[max@base simple_example]$ ls
Makefile  README.md  simple_example  simple_example.c  simple_example.o
[max@base simple_example]$ make clean
rm -f *.o simple_example
[max@base simple_example]$ make
gcc -c -Wall -I../../include -I../include -D_REENTRANT   simple_example.c -DDEBUG -g -O0
gcc -o simple_example simple_example.o -L -lc -lulfius -lorcania -L../../src -lyder
[max@base simple_example]$ ./simple_example 
2021-03-27T19:37:29Z - simple_example INFO: Starting simple_example
2021-03-27T19:37:29Z - simple_example DEBUG: Start framework on port 8537
^C
[max@base simple_example]$ make
gcc -c -Wall -I../../include -I../include -D_REENTRANT   simple_example.c -DDEBUG -g -O0
gcc -o simple_example simple_example.o -L -lc -lulfius -lorcania -L../../src -lyder
[max@base simple_example]$ ./simple_example 
2021-03-27T19:37:35Z - simple_example INFO: Starting simple_example
2021-03-27T19:37:35Z - simple_example DEBUG: Start framework on port 8537

http://localhost:8537/empty

Page not found, do what you want

http://localhost:8537/param/1

Page not found, do what you want

System (please complete the following information):

babelouest commented 3 years ago

Hello @BaseMax ,

As mentioned in the documentation where all the endpoints are listed, all the endpoints provided by the simple example code start with the prefix /test:

That's because all the endpoints declaration contain PREFIX in the prefix parameter:

#define PREFIX "/test"
ulfius_add_endpoint_by_val(&instance, "GET", PREFIX, "/empty", 0, &callback_get_empty_response, NULL);
ulfius_add_endpoint_by_val(&instance, "GET", PREFIX, "/param/:foo", 0, &callback_all_test_foo, "user data 1");
BaseMax commented 3 years ago

Dear Nicolas,

Thanks a lot. You saved my day. :+1: :heart: @babelouest