A minimal and fast RESTful API potentially useful for developing mock APIs with basic CRUD (create/read/update/delete) functionality. Written in C using Unix websockets, POSIX threads for multi-threaded server and integrated with SQLite.
docker
docker compose
./run_container
libsqlite3-dev
make
gcc
./run_locally
You can define your model at the xml file named models.xml
. A user model is provided as example for a database table:
<model name="users">
<col name="name">TEXT</col>
<col name="surname">TEXT</col>
<col name="age">INT</col>
<col name="height">REAL</col>
</model>
In the main.c
file, start the server with create_server(server_socket, "<ip-adress>", <port>, <max_number_of_connections>)
. Default IP address is 0.0.0.0, default port is 9002 and default maximum number of simultaneous connections is 10.
A simple Python file located in tests/tests.py
can be used to test each endpoint.
The server should be available at http://localhost:9002
.
Contains the server settings. Currently, the only setting is ALLOWED_HOSTS, which contains an array of strings corresponding to the accepted client IP addresses.
Contains the database model. On this example, the model consists of a simple "user" table with fields "name" and "surname". Example of an user entry in JSON format:
{
"id": 1,
"name": "Giga",
"surname": "Chad",
"age": 29
}
Contains the method to automatically generate basic CRUD routes. Example:
GET /
- root with "Hello world" message
GET /users
- lists all users in .json format
GET /users/<id>
- list user data by its id
PUT /users/<id>
- update user data by its id
DELETE /users/<id>
delete user by its id
POST /users
- creates a new user
Integrates the requests from the HTTP methods to the SQLite database and parses JSON data.
The views related to each route and its respective HTTP methods, performing calls to the database.
Contains functions that implement a multi-threaded server using Unix sockets and POSIX threads.