Skip to content

sumeetmathpati/hosted-pub-server

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

42 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation


Logo

Hosted Pub Server

The one server, to serve them all

Table of Contents

Live Server

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.

Features

  • Serving static files.
  • Serve a REST API (in JSON).
  • Rendering HTML pages.
  • Authentication with JWT.
  • Compile Dart Code to Javascript
  • Downlaod packages from server.

Implemented API endpoints

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.

Running Server

To run the server, enter the commands

git clone https://gitlab.com/sumeetmathpati/hosted-pub-server.git
cd hosted-pub-server
dart run

Server Configuration

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.

API Documentation

You can check API example documentation here.

Example Queries

Please note that I've used curl to make requests, you can also use GUI tool like Postman.

API Queries

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?

Get the list of all packages

curl -H "Authorization: Bearer <YOUR_TOKEN>" 'http://localhost:8080/api/packages'

Get the information of specific package

curl -H "Authorization: Bearer <YOUR_TOKEN>" 'http://localhost:8080/api/packages/provider'

Get the information of certain package with specific version.

curl -H "Authorization: Bearer <YOUR_TOKEN>" 'http://localhost:8080/api/packages/provider/versions/5.0.0'

Download Package

curl -H "Authorization: Bearer <YOUR_TOKEN>" 'localhost:8080/package/flutter_bloc-6.1.3.tar.gz' --output ./flutter_bloc-6.1.3.tar.gz

Authentication Queries

Note that, to use authentication features, enable it in setting file first.

Register User

curl --request POST --data '{"email": "user@test.com", "password": "password"}' http://localhost:8080/auth/register

Get Auth Token (For already registered user)

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

Logout User

curl --request POST -H "Authorization: Bearer <YOUR_TOKEN>" http://localhost:8080/auth/logout 

Converting to JS

We can convert ehe dart code into JS with dart2js package.