Crates.io | apigen |
lib.rs | apigen |
version | 0.3.1 |
source | src |
created_at | 2024-10-17 23:09:40.78787 |
updated_at | 2024-11-13 23:28:41.063293 |
description | A tool to genearate REST API written in Rust |
homepage | https://github.com/Pulko/apigen |
repository | https://github.com/Pulko/apigen |
max_upload_size | |
id | 1413687 |
size | 63,783 |
This project is a Rust-based API generator that allows you to generate a complete API based on a given schema in JSON format. It is designed to support multiple backends and database configurations, currently supporting PostgreSQL templates.
Cargo.toml
, .gitignore
, etc.).capitalize_first_letter
, pluralize
, and diesel_type
for template rendering.To check if Rust is installed, run:
rustc --version
Clone the repository:
git clone <your-repo-url>
cd api_generator
Prepare your API schema in JSON format. An example schema:
{
"entities": [
{
"name": "User",
"fields": [
{ "name": "id", "field_type": "i32" },
{
"name": "username",
"field_type": "String"
}
]
},
{
"name": "Post",
"fields": [
{ "name": "id", "field_type": "i32" },
{
"name": "title",
"field_type": "String"
},
{
"name": "body",
"field_type": "String"
},
{
"name": "author_id",
"field_type": "i32"
}
]
}
]
}
Run the apigen:
apigen '<api_schema_json>'
Replace <api_schema_json>
with your actual JSON schema. For example:
apigen '{"entities":[{"name":"User","fields":[{"name":"id","field_type":"i32"},{"name":"username","field_type":"String"}]}]}'
The generated API will be saved in the output
directory. The output folder will contain:
Cargo.toml
file.gitignore
and Dockerfile
.You can also run the API generator using Docker. You can run the API generator using the following command:
docker run --rm -v "$PWD:/usr/src/app" vzdbovich455/apigen:0.3.0 '<api_schema_json>'
Replace <api_schema_json>
with your actual JSON schema.
Example:
docker run --rm -v "$PWD:/usr/src/app" vzdbovich455/apigen:0.3.0 '{"entities":[{"name":"User","fields":[{"name":"id","field_type":"i32"},{"name":"username","field_type":"String"}]}]}'
The project uses a TemplateConfig
to load template files depending on the selected database backend. By default, it uses PostgreSQL templates located in the templates/postgres/
directory.
If you want to extend the project to support more databases or backends, you can:
templates/<backend>/
directory.TemplateConfig
to point to your new templates.This project is licensed under the MIT License. See the LICENSE file for details.