Getting Started
Learn how to install and set up your first Azura API.
Installation
Install Azura using your favorite package manager:
bash
npm install @atosjs/azura
TypeScript Support
Azura is built with TypeScript and includes type definitions. No need to install additional types.
Your First API
Create a new file named index.ts
in your project root and add the following code:
typescript
import { AzuraServer } from '@atosjs/azura';
// Create a new instance of the server
const app = new AzuraServer();
// Define a simple route
app.get('/hello', (req, res) => {
res.json({ message: 'Hello World!' });
});
// Start the server
app.listen(3000);
console.log('Server is running at http://localhost:3000');
Run your application:
bash
npx ts-node index.ts
Visit http://localhost:3000/hello
in your browser or use a tool like curl or Postman to make a request:
bash
curl http://localhost:3000/hello
You should see the following response:
json
{ "message": "Hello World!" }
Using Decorators
Azura provides a set of decorators to simplify API development. Here's how to use them:
typescript
import { AzuraServer, Controller, Get, Post, Body } from '@atosjs/azura';
// Create a new instance of the server
const app = new AzuraServer();
// Define a controller
@Controller('/users')
class UserController {
@Get('/')
getUsers() {
return { users: [{ id: 1, name: 'John' }, { id: 2, name: 'Jane' }] };
}
@Post('/')
createUser(@Body() userData: any) {
return { message: 'User created', user: userData };
}
}
// Register the controller
app.load([UserController]);
// Start the server
app.listen(3000);
TypeScript Configuration
To use decorators, make sure to enable
experimentalDecorators
and emitDecoratorMetadata
in your tsconfig.json
.Configuration
Create an azura.config.ts
file in your project root to configure your server:
typescript
import { AzuraConfig } from '@atosjs/azura';
const config: AzuraConfig = {
server: {
port: 8080,
cluster: true, // Enable cluster mode for better performance
},
plugins: {
cors: {
enabled: true,
origin: '*',
},
compression: {
enabled: true,
},
},
};
export default config;
Azura will automatically load this configuration when you create a new server instance.
Next Steps
Now that you have your first Azura API up and running, explore the following topics to learn more:
- Core Concepts - Understand the architecture of Azura
- Routing - Learn how to define complex routes
- Database Integration - Connect your API to a database
- Authentication - Secure your API
- Plugins - Extend Azura with plugins