The one server, to serve them all
- Live Server
- Features
- Implemented API endpoints
- Running Server
- Server Configuration
- API Documentation
- Example Queries
- Converting to JS
Don't want to clone and run? You can try the live server here. You can try all the queries given below to this server.
- Serving static files.
- Serve a REST API (in JSON).
- Rendering HTML pages.
- Authentication with JWT.
- Compile Dart Code to Javascript
- Downlaod packages from server.
Routes | Description | If authentication is enabled |
---|---|---|
GET /api/packages/ |
Get list of packages. | Requires Bearer token. |
GET /api/packages/<PACKAGE> |
Get the information of specific package. | Requires Bearer token. |
GET /api/packages/<PACKAGE>/versions/<VERSION> |
Get the information of certain package with specific version. | Requires Bearer token. |
POST /auth/register |
Register user. | Requires email id and password. |
POST /auth/login |
Get token. | Requires email id and password. |
POST /auth/logout |
Logout. | Requires Bearer token. |
GET /packages/<PACKAGE> |
This serves the packages stored in package folder in the root directory. | Requires Bearer token. |
To run the server, enter the commands
git clone https://gitlab.com/sumeetmathpati/hosted-pub-server.git
cd hosted-pub-server
dart run
The file in lib/src/settings.dart
is used to store configurations for the server.
You can use -h
command line argument to pass hostname.
You can check API example documentation here.
Please note that I've used curl to make requests, you can also use GUI tool like Postman.
If you are not using authentication for API (i.e. if it's disabled in setting file), just remove header "Authorization: Bearer <YOUR_TOKEN>"
in each query below. Example, just use curl http://localhost:8080/api/packages
instead of curl -H "Authorization: Bearer <YOUR_TOKEN>" 'http://localhost:8080/api/packages'
.
See this to know about How to get token?
curl -H "Authorization: Bearer <YOUR_TOKEN>" 'http://localhost:8080/api/packages'
curl -H "Authorization: Bearer <YOUR_TOKEN>" 'http://localhost:8080/api/packages/provider'
curl -H "Authorization: Bearer <YOUR_TOKEN>" 'http://localhost:8080/api/packages/provider/versions/5.0.0'
curl -H "Authorization: Bearer <YOUR_TOKEN>" 'localhost:8080/package/flutter_bloc-6.1.3.tar.gz' --output ./flutter_bloc-6.1.3.tar.gz
Note that, to use authentication features, enable it in setting file first.
curl --request POST --data '{"email": "user@test.com", "password": "password"}' http://localhost:8080/auth/register
To get the use id user@test.com
and password password
.
curl --request POST --data '{"email": "user@test.com", "password": "password"}' http://localhost:8080/auth/login
curl --request POST -H "Authorization: Bearer <YOUR_TOKEN>" http://localhost:8080/auth/logout
We can convert ehe dart code into JS with dart2js package.