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.08k stars 182 forks source link

ulfius_add_endpoint_by_val() url_prefix VS. url_format #249

Closed dancesWithCycles closed 1 year ago

dancesWithCycles commented 1 year ago

Hi folks, Thank you so much for maintaining this repository! I am reading this API specification and wondering how to use url_prefix VS. url_format in int ulfius_add_endpoint_by_val.

I like to transform the following existing REST API to ulfius.

/users/login GET /users/info GET /users/[userID]/info GET /users/update POST /users/create POST /users/email POST /registration/[uuid] GET /password/reset/[uuid] GET /password/reset POST /users/password/update POST /users/[id]/delete DELETE

You find parameters in square brackets and the HTML method as suffix.

What would be your suggestion on how to use prefix and format? Would you make e.g. users, registration and password a prefix and e.g. login, info, update, create, email, reset, update and delete a format?

Thank you so much for sharing!

Cheers!

babelouest commented 1 year ago

The difference between the parameters url_prefix and url_format is that the url_format accepts variables, when the url_prefix doesn't.

I added the url_prefix value to make the endpoints configuration more readable if you intend to use large urls, but always with the same prefix, such as:

in that case, using the url_prefix value myApp/api/v1 makes sense, so your url_format values can focus on what's important.

In your case, it's up to you whether you prefer using different url_prefix values depending on their goal (/users, /registration, /password) or not.

There is no better solution, and both solutions (with or without url_prefix) are equivalent.

dancesWithCycles commented 1 year ago

Cheers @babelouest for the explanation. Should be crystal clear by now.