rest-api-C
rest-api-C copied to clipboard
👽 A "simple" restful api make in pure C
A Simple RESTful Web Server in PURE C
RESTful web server in C using libmicrohttpd, a lightweight HTTP server library.
For a detailed example, you can refer to the libmicrohttpd manual.
Why Choose C for This Project?
I've deliberately chosen the C programming language for this project to challenge myself and revisit my programming roots. C was my first language, and it remains my favorite. Additionally, C finds extensive use in embedded systems and real-time applications, which are areas I particularly enjoy exploring as a hobbyist.
My primary goal was to gain a deeper understanding of how APIs function under the hood and how they communicate with the underlying operating system. The C language is exceptionally suited for this purpose due to its low-level nature and direct interaction with hardware and system resources.
Postgres Database
In this project, I'm using a Postgres database to store user information. The database is hosted on cloud in the supabase, and the server communicates with it using the libpq library.
How to Run the Server
Prerequisites:
- [x] Docker installed on your machine (Optional)
- [x] GCC compiler installed
- [x] Make utility installed
Step-by-Step:
-
Clone the Repository
git clone https://github.com/PedroFnseca/rest-api-C.git -
Navigate to the Project Directory
cd rest-api-C -
Update the Database Credentials
- Open the
pg.hfile in thesrcdirectory. - Update the variables with your database credentials.
- Open the
-
Running the Server:
- Using Docker:
docker build -t rest-api-c . docker run -d -p 8080:80 --name rest-api-c rest-api-c - Without Docker (Linux):
./main_run.sh - Without Docker (Windows):
make ./bin/main
- Using Docker:
-
Access the API at http://localhost:8080
Endpoints
This RESTful web server provides the following endpoints.
- GET /users: Retrieve a list of users.
- GET /users/{id}: Retrieve detailed information about a specific user.
- POST /users: Create a new user.
- PUT /users/{id}: Update information for a specific user.
- DELETE /users/{id}: Delete a user.