Skip to content

Commit 66003b6

Browse files
authored
Merge branch 'loco-rs:master' into feat/update-user-data-endpoint
2 parents b65b2c7 + cd14cac commit 66003b6

File tree

13 files changed

+241
-12
lines changed

13 files changed

+241
-12
lines changed

Cargo.toml

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,6 @@ version = "0.16.3"
1313
description = "The one-person framework for Rust"
1414
homepage = "https://loco.rs/"
1515
documentation = "https://docs.rs/loco-rs"
16-
authors = ["Dotan Nahum <dotan@rng0.io>", "Elad Kaplan <kaplan.elad@gmail.com>"]
1716
repository = "https://github.com/loco-rs/loco"
1817
license.workspace = true
1918
edition.workspace = true

README-pt_BR.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@
1616

1717
</div>
1818

19-
[English](./README.md) · [中文](./README-zh_CN.md) · [Français](./README.fr.md) · Portuguese (Brazil) ・ [日本語](./README.ja.md) · [한국어](./README.ko.md) · [Русский](./README.ru.md)
19+
[English](./README.md) · [中文](./README-zh_CN.md) · [Français](./README.fr.md) · Portuguese (Brazil) ・ [日本語](./README.ja.md) · [한국어](./README.ko.md) · [Русский](./README.ru.md) · [Español](./README.es.md)
2020

2121

2222
## O que é o Loco?

README-zh_CN.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@
1111

1212
</div>
1313

14-
[English](./README.md) · 中文 · [Français](./README.fr.md) · [Portuguese (Brazil)](./README-pt_BR.md)[日本語](./README.ja.md) · [한국어](./README.ko.md) · [Русский](./README.ru.md)
14+
[English](./README.md) · 中文 · [Français](./README.fr.md) · [Portuguese (Brazil)](./README-pt_BR.md)[日本語](./README.ja.md) · [한국어](./README.ko.md) · [Русский](./README.ru.md) · [Español](./README.es.md)
1515

1616
Loco 是一个用 Rust 编写的 Web 框架,类似于 Rails。Loco 提供快速构建 Web 应用的功能,并且允许创建自定义任务,可以通过 CLI 运行。
1717

README.es.md

Lines changed: 117 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,117 @@
1+
<div align="center">
2+
3+
<img src="https://github.com/loco-rs/loco/assets/83390/992d215a-3cd3-42ee-a1c7-de9fd25a5bac"/>
4+
5+
<h1>Bienvenido a Loco</h1>
6+
7+
<h3>
8+
<!-- <snip id="description" inject_from="yaml"> -->
9+
🚂 Loco es Rust on Rails.
10+
<!--</snip> -->
11+
</h3>
12+
13+
[![crate](https://img.shields.io/crates/v/loco-rs.svg)](https://crates.io/crates/loco-rs)
14+
[![docs](https://docs.rs/loco-rs/badge.svg)](https://docs.rs/loco-rs)
15+
[![Discord channel](https://img.shields.io/badge/discord-Join-us)](https://discord.gg/fTvyBzwKS8)
16+
17+
</div>
18+
19+
Español · [English](./README.md) · [中文](./README-zh_CN.md) · [Français](./README.fr.md) · [Português (Brasil)](./README-pt_BR.md) · [日本語](./README.ja.md) · [한국어](./README.ko.md) · [Русский](./README.ru.md) · Español
20+
21+
## ¿Qué es Loco?
22+
23+
`Loco` está fuertemente inspirado en Rails. Si conoces Rails y Rust, te sentirás como en casa. Si solo conoces Rails y eres nuevo en Rust, encontrarás Loco refrescante. No asumimos que conozcas Rails.
24+
25+
Para una explicación más profunda de cómo funciona Loco, incluyendo guías detalladas, ejemplos y referencias de la API, consulta nuestro [sitio de documentación](https://loco.rs).
26+
27+
## Características de Loco
28+
29+
* `Convención sobre configuración:` Al igual que Ruby on Rails, Loco enfatiza la simplicidad y la productividad al reducir la necesidad de código repetitivo. Utiliza valores predeterminados sensatos, permitiendo a los desarrolladores centrarse en la lógica de negocio en lugar de perder tiempo en la configuración.
30+
31+
* `Desarrollo rápido:` Loco está diseñado para una alta productividad del desarrollador, reduciendo el código repetitivo y proporcionando APIs intuitivas, permitiendo iterar rápidamente y construir prototipos con un esfuerzo mínimo.
32+
33+
* `Integración ORM:` Modela tu negocio con entidades robustas, eliminando la necesidad de escribir SQL. Define relaciones, validaciones y lógica personalizada directamente en tus entidades para una mayor mantenibilidad y escalabilidad.
34+
35+
* `Controladores:` Maneja parámetros de solicitudes web, cuerpo, validación y renderiza una respuesta consciente del contenido. Usamos Axum para el mejor rendimiento, simplicidad y extensibilidad. Los controladores también permiten construir middlewares fácilmente, que pueden usarse para agregar lógica como autenticación, registro o manejo de errores antes de pasar las solicitudes a las acciones principales del controlador.
36+
37+
* `Vistas:` Loco puede integrarse con motores de plantillas para generar contenido HTML dinámico a partir de plantillas.
38+
39+
* `Trabajos en segundo plano:` Realiza trabajos intensivos en computación o I/O en segundo plano con una cola respaldada por Redis o con hilos. Implementar un worker es tan simple como implementar una función perform para el trait Worker.
40+
41+
* `Planificador:` Simplifica el tradicional y a menudo engorroso sistema crontab, facilitando y haciendo más elegante la programación de tareas o scripts de shell.
42+
43+
* `Mailers:` Un mailer enviará correos electrónicos en segundo plano usando la infraestructura de background worker de Loco. Todo será transparente para ti.
44+
45+
* `Almacenamiento:` En Loco Storage, facilitamos el trabajo con archivos a través de múltiples operaciones. El almacenamiento puede ser en memoria, en disco o usar servicios en la nube como AWS S3, GCP y Azure.
46+
47+
* `Caché:` Loco proporciona una capa de caché para mejorar el rendimiento de la aplicación almacenando datos de acceso frecuente.
48+
49+
Para ver más características de Loco, consulta nuestro [sitio de documentación](https://loco.rs/docs/getting-started/tour/).
50+
51+
## Primeros pasos
52+
<!-- <snip id="quick-installation-command" inject_from="yaml" template="sh"> -->
53+
```sh
54+
cargo install loco
55+
cargo install sea-orm-cli # Solo si necesitas base de datos
56+
```
57+
<!-- </snip> -->
58+
59+
Ahora puedes crear tu nueva app (elige "`SaaS` app").
60+
61+
<!-- <snip id="loco-cli-new-from-template" inject_from="yaml" template="sh"> -->
62+
```sh
63+
❯ loco new
64+
✔ ❯ ¿Nombre de la app? · miapp
65+
✔ ❯ ¿Qué te gustaría construir? · App SaaS con renderizado del lado del cliente
66+
✔ ❯ Selecciona un proveedor de BD · Sqlite
67+
✔ ❯ Selecciona el tipo de worker en segundo plano · Async (tareas async in-process con tokio)
68+
69+
🚂 App Loco generada exitosamente en:
70+
miapp/
71+
72+
- assets: Has seleccionado `clientside` para la configuración de tu servidor de assets.
73+
74+
Siguiente paso, construye tu frontend:
75+
$ cd frontend/
76+
$ npm install && npm run build
77+
```
78+
<!-- </snip> -->
79+
80+
Ahora entra en tu `miapp` y arranca tu app:
81+
<!-- <snip id="starting-the-server-command-with-output" inject_from="yaml" template="sh"> -->
82+
```sh
83+
$ cargo loco start
84+
85+
▄ ▀
86+
▀ ▄
87+
▄ ▀ ▄ ▄ ▄▀
88+
▄ ▀▄▄
89+
▄ ▀ ▀ ▀▄▀█▄
90+
▀█▄
91+
▄▄▄▄▄▄▄ ▄▄▄▄▄▄▄▄▄ ▄▄▄▄▄▄▄▄▄▄▄ ▄▄▄▄▄▄▄▄▄ ▀▀█
92+
██████ █████ ███ █████ ███ █████ ███ ▀█
93+
██████ █████ ███ █████ ▀▀▀ █████ ███ ▄█▄
94+
██████ █████ ███ █████ █████ ███ ████▄
95+
██████ █████ ███ █████ ▄▄▄ █████ ███ █████
96+
██████ █████ ███ ████ ███ █████ ███ ████▀
97+
▀▀▀██▄ ▀▀▀▀▀▀▀▀▀▀ ▀▀▀▀▀▀▀▀▀▀ ▀▀▀▀▀▀▀▀▀▀ ██▀
98+
▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀
99+
https://loco.rs
100+
101+
listening on port 5150
102+
```
103+
<!-- </snip> -->
104+
105+
## Proyectos impulsados por Loco
106+
107+
* [SpectralOps](https://spectralops.io) - varios servicios impulsados por el framework Loco
108+
109+
* [Nativish](https://nativi.sh) - backend de la app impulsado por el framework Loco
110+
111+
## Contribuidores ✨
112+
113+
Gracias a estas personas maravillosas:
114+
115+
<a href="https://github.com/loco-rs/loco/graphs/contributors">
116+
<img src="https://contrib.rocks/image?repo=loco-rs/loco" />
117+
</a>

README.fr.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@
55
<h1>Loco vous souhaite la bienvenue</h1>
66

77
<h3>
8-
🚂 Loco c'est Rust on Rails.
8+
🚂 Loco c'est Rust on Rails.
99
</h3>
1010

1111
[![crate](https://img.shields.io/crates/v/loco-rs.svg)](https://crates.io/crates/loco-rs)
@@ -14,7 +14,7 @@
1414

1515
</div>
1616

17-
[English](./README.md) · [中文](./README-zh_CN.md) · Français · [Portuguese (Brazil)](./README-pt_BR.md)[日本語](./README.ja.md) · [한국어](./README.ko.md) · [Русский](./README.ru.md)
17+
[English](./README.md) · [中文](./README-zh_CN.md) · Français · [Portuguese (Brazil)](./README-pt_BR.md)[日本語](./README.ja.md) · [한국어](./README.ko.md) · [Русский](./README.ru.md) · [Español](./README.es.md)
1818

1919
## À propos de Loco
2020
`Loco` est fortement inspiré de Rails. Si vous connaissez Rails et Rust, vous vous sentirez chez vous. Si vous ne connaissez que Rails et que vous êtes nouveau sur Rust, vous trouverez Loco rafraîchissant. Nous ne supposons pas que vous connaissez Rails.

README.ko.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@
1414

1515
</div>
1616

17-
[English](./README.md) · [中文](./README-zh_CN.md) · [Français](./README.fr.md) · [Portuguese (Brazil)](./README-pt_BR.md)[日本語](./README.ja.md) · 한국어 · [Русский](./README.ru.md)
17+
[English](./README.md) · [中文](./README-zh_CN.md) · [Français](./README.fr.md) · [Portuguese (Brazil)](./README-pt_BR.md)[日本語](./README.ja.md) · 한국어 · [Русский](./README.ru.md) · [Español](./README.es.md)
1818

1919

2020
## Loco란?

README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@
1717
</div>
1818

1919

20-
English · [中文](./README-zh_CN.md) · [Français](./README.fr.md) · [Portuguese (Brazil)](./README-pt_BR.md)[日本語](./README.ja.md) · [한국어](./README.ko.md) · [Русский](./README.ru.md)
20+
English · [中文](./README-zh_CN.md) · [Français](./README.fr.md) · [Portuguese (Brazil)](./README-pt_BR.md)[日本語](./README.ja.md) · [한국어](./README.ko.md) · [Русский](./README.ru.md) · [Español](./README.es.md)
2121

2222

2323
## What's Loco?

README.ru.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@
1616

1717
</div>
1818

19-
[English](./README.md) · [中文](./README-zh_CN.md) · [Français](./README.fr.md) · [Portuguese (Brazil)](./README-pt_BR.md)[日本語](./README.ja.md) · Русский
19+
[English](./README.md) · [中文](./README-zh_CN.md) · [Français](./README.fr.md) · [Portuguese (Brazil)](./README-pt_BR.md)[日本語](./README.ja.md) · Русский · [Español](./README.es.md)
2020

2121

2222
## Что такое Loco?

docs-site/content/docs/getting-started/starters.md

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -45,6 +45,34 @@ Next step, build your frontend:
4545
4646
## Available Starters
4747
48+
### Command Line Options
49+
50+
Print the command line options:
51+
52+
```console
53+
$ loco new --help
54+
Create a new Loco app
55+
56+
Usage: loco[EXE] new [OPTIONS]
57+
58+
Options:
59+
-p, --path <PATH> Local path to generate into [default: .]
60+
-v, --verbose <VERBOSE> Verbosity level [default: ERROR]
61+
-n, --name <NAME> App name
62+
-t, --template <TEMPLATE> Starter template
63+
--db <DB> DB Provider [possible values: sqlite, postgres]
64+
--bg <BG> Background worker configuration [possible values: async, queue, blocking]
65+
--assets <ASSETS> Assets serving configuration [possible values: serverside, clientside]
66+
-h, --help Print help
67+
-V, --version Print version
68+
```
69+
70+
Example starter with a SQLite database, async background worker, and server side assets:
71+
72+
```sh
73+
loco new --db sqlite --bg async --assets serverside
74+
```
75+
4876
### SaaS Starter
4977
5078
The SaaS starter is an all-included set up for projects requiring both a UI and a REST API. For the UI this starter supports a client-side app or classic server-side templates (or a combination).

docs-site/content/docs/the-app/controller.md

Lines changed: 89 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -571,7 +571,7 @@ async fn current(
571571
}
572572
```
573573

574-
Additionally, you can fetch the current user by replacing auth::JWT with `auth::ApiToken<users::Model>`.
574+
Additionally, you can fetch the current user by replacing auth::JWT with `auth::JWTWithUser<users::Model>`.
575575

576576
#### API Key
577577

@@ -1243,6 +1243,94 @@ impl PaginationResponse {
12431243
}
12441244
```
12451245

1246+
## Custom Extractors
1247+
1248+
When it is necessary to validate request information contained in the request header, a custom extractor can be implemented for this purpose. For example, in a multi-tenant application that includes the current tenant identifier in the headers, the extractor should retrieve the value, verify its validity in the database, and ensure that the user is authorized to access it. To implement a custom extractor, it is required to implement one of the following traits: FromRequest or FromRequestParts.
1249+
1250+
```rust
1251+
use axum::{
1252+
extract::FromRequestParts,
1253+
extract::FromRef,
1254+
http::{request::Parts, StatusCode},
1255+
};
1256+
use loco_rs::prelude::*;
1257+
use sea_orm::{EntityTrait, DatabaseConnection};
1258+
1259+
use loco_rs::app::AppContext;
1260+
use crate::models::_entities::companies; // Adjust to your strucuture
1261+
1262+
#[derive(Debug, Clone)]
1263+
pub struct CompanyContext(pub i32, pub String);
1264+
1265+
impl<S> FromRequestParts<S> for CompanyContext
1266+
where
1267+
AppContext: FromRef<S>,
1268+
S: Send + Sync,
1269+
{
1270+
type Rejection = (StatusCode, String);
1271+
1272+
async fn from_request_parts(
1273+
parts: &mut Parts,
1274+
state: &S
1275+
) -> Result<Self, Self::Rejection> {
1276+
1277+
// 1. get header
1278+
let nickname = parts.headers
1279+
.get("x-my-company")
1280+
.and_then(|h| h.to_str().ok())
1281+
.ok_or((
1282+
StatusCode::BAD_REQUEST,
1283+
"Missing X-MY-COMPANY".to_string(),
1284+
))?
1285+
.to_string();
1286+
1287+
let ctx = AppContext::from_ref(state);
1288+
let db: &DatabaseConnection = &ctx.db;
1289+
1290+
// 3. Search tenant on database
1291+
let company = companies::Entity::find()
1292+
.filter(companies::Column::Uuid.eq(nickname.clone()))
1293+
.one(db)
1294+
.await
1295+
.map_err(|e| {
1296+
(
1297+
StatusCode::INTERNAL_SERVER_ERROR,
1298+
format!("DB error: {}", e),
1299+
)
1300+
})?
1301+
.ok_or((
1302+
StatusCode::NOT_FOUND,
1303+
"Company not found".to_string(),
1304+
))?;
1305+
1306+
Ok(CompanyContext(company.id, nickname))
1307+
}
1308+
}
1309+
1310+
```
1311+
1312+
After that just added to your action.
1313+
1314+
```rust
1315+
#[debug_handler]
1316+
pub async fn add(
1317+
CompanyContext(company_id, nickname): CompanyContext,
1318+
State(ctx): State<AppContext>,
1319+
Json(params): Json<Params>,
1320+
) -> Result<Response> {
1321+
1322+
// Action logic ...
1323+
1324+
1325+
format::json({ message: "added!" })
1326+
}
1327+
```
1328+
1329+
<div class="infobox">
1330+
More information about extractors can be found in the <a href="https://docs.rs/axum/latest/axum/extract/index.html#the-order-of-extractors">axum documentation</a>.
1331+
</div>
1332+
1333+
12461334
# Testing
12471335

12481336
When testing controllers, the goal is to call the router's controller endpoint and verify the HTTP response, including the status code, response content, headers, and more.

0 commit comments

Comments
 (0)