Core

HTTP Server

Built-in HTTP server with zero configuration.

1 min readDocumentationEdit this page

Overview#

typescript
import { Application } from '@AxilJS/core'
 
const app = new Application()
 
app.get('/hello', (req, res) => {
  res.json({ message: 'Hello from AxilJS' })
})
 
app.listen()

Configuration#

typescript
const app = new Application({
  server: { port: 3000, host: '0.0.0.0' },
  env: 'development',
  logging: true
})

Request object#

typescript
app.get('/users', (req, res) => {
  req.method   // 'GET'
  req.path     // '/users'
  req.query    // { page: '1' }
  req.params   // { id: '42' }
  req.headers  // request headers
  req.body     // parsed body
  req.ip       // client IP
  req.locals   // middleware data
})

Response object#

typescript
res.json({ data: 'value' })
res.status(201).json({ created: true })
res.text('Hello')
res.html('<h1>Hello</h1>')
res.redirect('/other')
res.header('X-Custom', 'value').json({ ok: true })

Graceful shutdown#

typescript
await app.listen()
await app.close()

Note

The server catches all unhandled errors and returns HTTP 500 without crashing.

Help improve the documentation

AxilJS is open source and documentation improvements are welcome.

AxilJS DocumentationMIT License · Built by SyntaxilitY