Skip to content

Commit 5b847dd

Browse files
authored
fix: Documentation problem fixed.
fix: documentation problem.
2 parents 407e35c + baacdf0 commit 5b847dd

4 files changed

Lines changed: 390 additions & 543 deletions

File tree

README.md

Lines changed: 69 additions & 114 deletions
Original file line numberDiff line numberDiff line change
@@ -6,13 +6,15 @@
66

77
**like the brain's powerful neural pathways, simple yet strong. 🧠**
88

9-
Axon is a backend library that aims to be simple and powerfull.
9+
Axon is a backend framework that aims to be simple and powerfull.
1010

1111
Currently Axon is 2X faster than Express. :D please checkout [Axon Benchmarks](./benchmarks/README.md)
1212

1313
[Axon telegram channel](https://t.me/axonjs)
1414

15-
Latest change: (v0.12.0)
15+
[Axon Documentation](https://axonjslabs.github.io/AxonJs/)
16+
17+
Latest change: (v0.13.0)
1618

1719
- Dependency injection
1820
Fixed some problems and dependency injection system redesigned.
@@ -51,123 +53,32 @@ Latest change: (v0.12.0)
5153
container.inspect();
5254
```
5355

54-
Past changes:
55-
56-
#### (v0.12.0)
57-
58-
- Dependency injection
59-
Axon's new feature is dependency injection for class methods and controller functions.
60-
support for class constructor and middlewar;es will add soon.
61-
How to use:
62-
1. Register your dependency into the Axon core:
63-
64-
```typescript
65-
// class instance
66-
core.registerDependencyValue('dependencyName', new DependencyClass(arg1, arg2));
67-
68-
// class with factory function (core will run factory function before injection process)
69-
core.registerDependencyFactory('dependencyName2', () => new DependencyClass());
70-
71-
// function
72-
core.registerDependencyValue('dependencyName3', dependencyFunction);
73-
74-
// Also you can register dependencies with name aliases
75-
core.registerDependencyValue(['depClass', 'classDep', 'DB'], new DependencyClass());
76-
```
77-
78-
2. Use you dependency in controller
79-
80-
```typescript
81-
// When you want to use dependencies, make sure you enter exact dependency name or alias
82-
// in 3rd argument of controller method or function into the object.
83-
interface IDependencies {
84-
DB: DependencyClass;
85-
dependencyName3: (...args: any[]) => any;
86-
}
87-
88-
class UserController extends BaseController {
89-
async index(req: Request<any>, res: Response, { DB, dependencyName3 }: IDependencies) {
90-
const result = dependencyName3();
91-
const db = DB.get();
92-
}
93-
}
94-
95-
// Or functional controller:
96-
const getUsers = async (
97-
req: Request<any>,
98-
res: Response,
99-
{ DB, dependencyName3 }: IDependencies
100-
) => {
101-
const result = dependencyName3();
102-
const db = DB.get();
103-
};
104-
105-
router.get('/users/class', [UserController, 'index']);
106-
router.get('/users/function', getUsers);
107-
```
108-
109-
#### (v0.11.0)
110-
111-
- Class-Based Controllers
112-
You can use the new generation of controllers in Axon.
113-
In class-based controllers you can use state managing of classes in your application without any instance making.
114-
More organized controllers!
115-
116-
```ts
117-
class UsersController extends BaseController {
118-
async index(req: Request<any>, res: Response) {
119-
return res.status(200).body({});
120-
}
121-
}
122-
123-
// [Class, Method]
124-
router.get('/users', [UsersController, 'index']);
125-
```
126-
127-
Your controller class must extends from BaseController, Otherwise the router will throw error.
128-
129-
```ts
130-
class UsersController {
131-
async index(req: Request<any>, res: Response) {
132-
return res.status(200).body({});
133-
}
134-
}
135-
136-
router.get('/users', [UsersController, 'index']);
137-
138-
// Error: Controller class must extends from BaseController
139-
```
140-
141-
#### (v0.10.0)
56+
## Installation 📥
14257

143-
- Cookie manager added to Axon.
144-
You can access cookie manager by importing AxonCookie class in your code.
145-
AxonCookie has some static methods for managing cookies easily.
146-
Example:
58+
Install Axon.js with npm
14759

148-
```ts
149-
import { AxonCookie } from '@axonlabs/core';
60+
```bash
61+
npm install @axonlabs/core
62+
```
15063

151-
AxonCookie.set(res, name, value, options);
152-
AxonCookie.parse(req);
153-
AxonCookie.clear(res, name, options);
154-
```
64+
## Create new project 🧰
15565

156-
#### (v0.9.0)
66+
Create new project using Axon CLI tool.
15767

158-
- Plugin system updated.
159-
- Project environment state added to core config.
160-
- Validation system added to router.
68+
```bash
69+
npm install -g @axonlabs/cli
70+
```
16171

162-
> [!WARNING]
163-
> @mr-mkz/axon deprecated and transferred to @axonlabs/core
72+
After installing Axon CLI you can manager your Axon apps in the fastest way.
16473

165-
## Installation 📥
74+
```bash
75+
axon create:project
76+
```
16677

167-
Install Axon.js with npm
78+
or also you can work with `npx`
16879

16980
```bash
170-
npm install @axonlabs/core
81+
npx @axonlabs/cli create:project
17182
```
17283

17384
## Benchmarks 🧪
@@ -176,6 +87,13 @@ You can checkout Axon benchmarks document and results from below link.
17687

17788
[Axon Benchmarks](./benchmarks/README.md)
17889

90+
| Name | Request | Response|
91+
|---------|-----------|---------|
92+
| Axon | 16146.45 | 42.79ms |
93+
| Express | 8865.71 | 45.89ms |
94+
95+
96+
17997
## Badges 📛
18098

18199
<p align="center">
@@ -223,25 +141,34 @@ You can checkout Axon benchmarks document and results from below link.
223141
- Default cors configuration method
224142
- Support https server
225143
- Auto validation handler (Yup, Zod, Joi)
144+
- Built-in dependency injection system.
145+
- Neuron Container, Special dependency injection container of Axon.
226146

227147
**More features soon...**
228148

229149
## Roadmap (still thinking) 🚦
230150

231151
- Response meta generator.
232152
- Auto error detector (maybe)
233-
- Default schemas.
234153
- Default database connection methods.
154+
- HTTP/2 support
155+
- HTTP/3 support
156+
- Websockets support
157+
- Queue workers
158+
- Event channels
235159
- Improve plugin system
236160
- Core versioning
237161
- Plugin dependencies
238162
- Improve AxonCore
239163
- Cleaner code
240164

165+
241166
## Documentation 📚
242167

243168
Currently Axon has a main core and a router class which you can make instance from router class every where you want and then gave the router instance to core to load routes.
244169

170+
[Axon Documentation](https://axonjslabs.github.io/AxonJs/)
171+
245172
More complete examples:
246173

247174
- [Typescript Example](./examples/index.ts)
@@ -355,11 +282,31 @@ Example:
355282
```js
356283
const controller = async (req, res) => {
357284
return res.status(200).body({
358-
message: 'Hello, World',
285+
message: 'Hello, World'
359286
});
360287
};
361288
```
362289

290+
```js
291+
class AuthController extends BaseController {
292+
async index(req, res) {
293+
return res.status(200).body({
294+
message: 'Hello, World'
295+
});
296+
}
297+
}
298+
```
299+
300+
Registering controllers:
301+
302+
```js
303+
// function controller
304+
router.get("/", controller);
305+
306+
// class controller
307+
router.get("/auth", [AuthController, "index"]);
308+
```
309+
363310
### Middleware 🚓
364311

365312
middleware is a function which runs before running controller for validations or some actions like this and you can use it in two ways.
@@ -369,13 +316,13 @@ middleware is a function which runs before running controller for validations or
369316
```js
370317
router
371318
.get('/', controller)
372-
.middleware(async (req, res, next) => next(), (timeout = 2000), (critical = true));
319+
.middleware(async (req, res, next) => next(), timeout = 2000, critical = true);
373320
```
374321
you can also use multiple middlewares for a route by repeating middleware function and middlewares will run in order.
375322
2. loading middleware as a global middleware in Axon core.
376323
- Example:
377324
```js
378-
core.globalMiddleware(async (req, res, next) => next(), (timeout = 2000), (critical = true));
325+
core.globalMiddleware(async (req, res, next) => next(), timeout = 2000, critical = true);
379326
```
380327
you can also use multiple middlewares in this way by adding middleware functions into an array (suggested method) or repeating this line of code.
381328

@@ -395,14 +342,20 @@ AxonJs has some types which can help you in developing your applications for aut
395342
- `Response`: Type of controller response param. (ServerResponse)
396343
- `Headers`: Type of response headers. (OutgoingHeaders)
397344
- `NextFunc`: Type of next function param in middleware.
398-
- `Controller`: Type of controller function.
345+
- `FuncController`: Type of controller function.
399346
- `Middleware`: Type of middleware function.
400347
- `HttpMethods`: Type of router http methods.
401348
- `RouterExceptionError`: Type of router exceptions.
402349
- `ValidationObj`: Required object for router auto validation process.
403350
- `ValidationConfig`: Config type of AxonValidator. (including joi, yup and zod config options)
404351
- `ValidationSchema`: Schema type of AxonValidator.
405352
- `ValidationTargets`: Target list of AxonValidator.
353+
- `CookieOptions`: Option type for Axon Cookie Manager class.
354+
- `Lifecycle`: Dependency lifecycle list.
355+
- `UnloadRouteParams`: Prop type of unloadRouteparams method of Axon core.
356+
- `AxonConfig`: Axon config type which used in `axon.config.*` as config object.
357+
- `AxonPlugin`: Axon plugin interface for implementation in plugins.
358+
- `PluginMode`: Plugin mode of Axon plugins.
406359

407360
### Axon Core logger (pino & pino-pretty)
408361

@@ -451,6 +404,8 @@ Configs:
451404
- `CORS`: object to change core cors settings. (type: AxonCorsConfig)
452405
- `HTTPS`: object to config server for https. (type: AxonHttpsConfig)
453406
- `MIDDLEWARE_TIMEOUT`: variable to set global timeout of waiting for middleware to response or call next function. (ms, default 10000ms)
407+
- `PROJECT_ENV`: Project environment type to manage features more secure and automatically in AxonCore.
408+
- `DEPENDENCY_CACHE`: Cache dependencies of controller, middleware handlers. (Currently dependency injection just support controllers)
454409

455410
### Running server 🔑
456411

0 commit comments

Comments
 (0)