A web server built using Shelf. Following features have been implemented:
- Serve a REST API in JSON
- Serve static files from the server
- Render HTML
- Compile Dart Code to Javascript
Perform the following operations to set up the project.
git clone https://github.com/ravgeetdhillon/dart_shelf_server_sample
pub get
nodemon
Nodemon is an NPM package used to watch for the changes in source code and restart the shelf server automatically. You can install it by doing
npm i -g nodemon
.
Visit http://localhost:8080 and make sure you see the following screen:
All of the configurable constants are present in lib/config/constants.dart
.
All the data related to API is stored in the data/api
directory.
Routes | Description |
---|---|
GET /posts |
Get all the posts |
GET /posts/{id} |
Get a single post identified by its id |
GET /files |
Get a list of files available on the server |
Use the /files
route to get the list of static files available on the server. Static files are stored in the files
directory.
Dart code is compiled to JS using the dart2js library. Nodemon automatically watches for the changes in lib
and bin
directories and runs dart2js -o public/assets/script.js lib/standalone/index.dart
.
MIT