- 0.2.0Latest
- 0.1.63
- 0.1.62
- 0.1.61
- 0.1.60
- 0.1.59
- 0.1.58
- 0.1.57
- 0.1.56
- 0.1.55
- 0.1.54
- 0.1.53
- 0.1.52
- 0.1.51
- 0.1.50
- 0.1.49
- 0.1.48
- 0.1.47
- 0.1.46
- 0.1.45
- 0.1.44
- 0.1.43
- 0.1.42
- 0.1.41
- 0.1.40
- 0.1.39
- 0.1.38
- 0.1.37
- 0.1.36
- 0.1.35
- 0.1.34
- 0.1.33
- 0.1.32
- 0.1.31
- 0.1.30
- 0.1.29
- 0.1.28
- 0.1.27
- 0.1.26
- 0.1.25
- 0.1.24
- 0.1.23
- 0.1.22
- 0.1.21
- 0.1.20
- 0.1.19
- 0.1.18
- 0.1.17
- 0.1.16
- 0.1.15
- 0.1.14
- 0.1.13
- 0.1.12
- 0.1.11
- 0.1.10
- 0.1.9
- 0.1.8
- 0.1.7
- 0.1.6
- 0.1.5
- 0.1.4
- 0.1.3
- 0.1.2
- 0.1.1
- 0.1.0
Cargo - Develop Web Applications the Way You Like!
Cargo is a web application framework with the right abstraction of helpful features to build web applications with Deno. It provides you a starting point and structure for your projects, yet allows flexibility for different needs. You can focus on developing awesome projects without getting bogged down by the lower-level details
How to use Cargo
Create a app.ts
file, import and call Cargo’s bootstrap function and add
required routes to your Applications:
// main.ts
import { bootstrap, Get } from "https://deno.land/x/cargo/mod.ts";
import { Get } from "https://deno.land/x/cargo/http/mod.ts";
const app = await bootstrap();
Get("/", (ctx) => {
return new Response("Hello World!");
});
app.run();
Run the application with deno run --allow-net --allow-read main.ts
and open
http://localhost:8000/hello
in your browser.
Middleware
Middleware allows you to do some work before and after the final route handler is called.
A simple example is to log the time for handling an incoming request. In the
main.ts
add the following code:
// main.ts
import { bootstrap } from "https://deno.land/x/cargo/mod.ts";
import { Get } from "https://deno.land/x/cargo/http/mod.ts";
const App = await bootstrap();
// Middleware on app level
App.middleware((ctx, next) => {
const startTime = Date.now();
// Calling the next function will continue with the middleware chain and wait for the response.
const response = await next(ctx);
const endTime = Date.now();
// Log the time difference before and after calling the next function ms.
console.log(endTime - startTime);
return response;
});
const HelloRoute = Get("/hello", (ctx) => {
return new Response("World!");
});
// Middleware on route level
HelloRoute.middleware((ctx, next) => {
// Doing work before the request is handled by the route.
const response = await next(ctx);
// Doing work after the request is handled by the route.
return response;
});
App.run();
Licence
MIT License
Contact
Feel free submit issues here on GitHub or reach out to me for any feedback at daniel.steuri@flowingones.ch