The c3-api
project is a simple C3 HTTP Server with routing. This project aims to provide a comprehensive and modular way to manage and manipulate HTTP communications.
Inspired from ArjixWasTaken/c3-simple-http
To install and set up the c3-api
project, follow these steps:
-
Clone the repository:
git clone https://github.com/velikoss/c3-api.git
-
Ensure you have the C3 compiler installed. You can find the installation instructions here.
To compile and run the project, use the following commands:
-
Compile the project:
c3c compile -O3 c3-api
-
Run the executable:
./c3api
To add routes to the server, follow these steps:
-
Define your routes using the appropriate HTTP verbs and handlers in your code. For example:
fn HttpResponse pong(HttpRequest req, HashMap(<String,String>) args) { HttpResponse res; res.status = HttpStatus.OK; res.body = string::new_format("Pong!\n", req.method, req.uri); return res; } fn HttpResponse pong1(HttpRequest req, HashMap(<String,String>) args) { HttpResponse res; res.status = HttpStatus.OK; res.body = string::new_format(args["pong"]!!, "\n", req.method, req.uri); return res; }
-
Add the routes in the main function in
main.c3
:fn int main(String[] args) { // TODO CONFIG String host = "127.0.0.1"; uint port = 8080; add_route("/ping", &pong); add_route("/ping/{pong}", &pong1); startServer(host, port)!!; return 0; }
To start the server, ensure your main function is set up correctly in main.c3
:
- Initialize and set the routes.
- Start the server.
Here are some planned features and improvements for the c3-api
project:
- 0. FIX MEMORY LEAKS: 3k requests spikes up RAM usage from 6Kb to 1.6Gb without any freeing. Any contributions and suggestions are welcomed.
- 1. Enhanced Routing: Implement advanced routing capabilities, including support for query parameters and wildcard routes.
- method(string, fn) instead of add_route(string, fn)
- 2. Middleware Support: Add support for middleware to handle tasks such as authentication, logging, and request validation.
- CORS
- JWT
- 3. HTTPS Support: Enable HTTPS support for secure communications.
- 4. Configuration Management: Develop a configuration management system to easily manage server settings and environment variables.
- 5. Testing Framework: Create a robust testing framework to ensure the reliability and stability of the API.
- 6. Documentation: Improve documentation with detailed examples and usage guides.
Contributions are welcome! Please follow these steps:
- Fork the repository.
- Create a new branch (
git checkout -b feature-branch
). - Commit your changes (
git commit -am 'Add new feature'
). - Push to the branch (
git push origin feature-branch
). - Create a new Pull Request.
This project is licensed under the MIT License. See the LICENSE file for details.
For questions or feedback, please contact velikoss@vk.com or Discord: @velikoss .