AL-REST is a lightweight class and event based rest server.
To run the code in the example do these steps
- Clone repo
- Run
npm install
- Run
npm start
- Admire webserver
- Edit code
- Repeat steps 3-5
Follow these steps, I don't care if there's a lot. Maybe I'll make a repo of this example, but I'm lazy :D
- Create new directory
- Run
npm init
and follow wizard- Set
node src/app.js
as test command
- Set
- Run
npm install git+https://github.com/AL1L/AL-REST.git
- Create these directories
- src
- src/endpoints
- data
- Create these files
- src/app.js
- src/endpoints/hello.js
- data/server.json
src/app.js:
import { Server } from "al-rest";
const server = new Server('data/server.js');
server.em.loader.loadDirectory('src/endpoints')
server.start();
src/endpoints/hello.js:
import { Url } from "url";
import { Request, Endpoint } from "al-rest";
// The name of the class doesn't matter
export default class HelloEndpoint extends Endpoint {
constructor(em) {
super(em);
this.meta({
name: 'Hello',
desc: 'Hello, World!'
});
}
canHandle(method, url) {
return url.path === '/';
}
handle(request) {
request.res.setMessage('Hello, world!');
}
}
data/server.json:
{
"host": "localhost",
"port": 3000
}
- Run
npm run test
- Yay!