Webmaker services API.
You will need to download and install:
# Clone the repo
git clone https://github.com/mozilla/api.webmaker.org
# change into project directory
cd api.webmaker.org
# install dependencies using npm
npm install
# copy default environment config
cp env.sample .env
# create a database; -U and -W are only necessary if your pg instance needs authentication
createdb -U dbusername -W dbuserpassword webmaker
# create tables; -U and -W are only necessary if your pg instance needs authentication
psql -U dbusername -W dbuserpassword -d webmaker -f scripts/create-tables.sql
In order to quickly get up and running for development purposes, you will also want to create at least one user by logging into your postgresql instance:
$> psql -d webmaker -U dbusername
and then issuing the following user record creation instruction:
pg> insert into users (id, username, language) VALUES (1, 'testuser', 'en-US');
This will let you call any of the API endpoints with userid 1
without running into
API errors due to missing users.
Migration scripts can be found in the migrations
folder.
You can run all the scripts in order with npm run migrate
or run each individually for a partial migration psql -U username -d dbname -f migrations/{migration_script}.sql
Start the server with npm start
You can view documentation by navigating to http://localhost:2015/docs
in your browser
Variable | Description | Default |
---|---|---|
API_HOST | The Host that Hapi should listen for connections on | 0.0.0.0 |
PORT | The port number that Hapi should listen for connections on | 2015 |
API_VERSION | The Version Number of the API, applied to newly created projects | 'dev' |
LOG_LEVEL | given a chosen level, log events only at or above that level. debug < info < warn < error < exception < stat | info |
POSTGRE_CONNECTION_STRING | A connection string to a PostgreSQL server | postgresql://localhost:5432/webmaker |
REDIS_URL | A connection string to a redis server | redis://localhost:6379 |
ID_SERVER_CONNECTION_STRING | A connection string to a Webmaker ID server | https://id.mofostaging.net |
THUMBNAIL_SERVICE_URL | The URL where webmaker-screenshot can be reached | undefined (screenshots disabled) |
PAGE_RENDER_URL | The URL where webmaker-desktop can be reached | undefined (must defined if screenshots enabled) |
If you are using a vanilla PostgreSQL instance, you will either need to allow unauthenticated connections, or modify the POSTGRE_CONNECTION_STRING
such that it is using the correct username and password, by using for following format instead of the one that is used in the sample.env
file:
export POSTGRE_CONNECTION_STRING=postgresql://username:password@localhost:5432/webmaker
For default installations, this will have username postgres
, with the password that you had to fill in during the PostgreSQL installation process.
The tests assume the user postgres
exists and has no password set. They also assume that a database named webmaker_testing
has been created, and that postgres
has owner permissions. Create the database with createdb -U postgres webmaker_testing
See the guide for configuring New Relic using environment variables to configure the New Relic agent
Variable | Description |
---|---|
MOCKED_AUTH | If used the server will bypass token validation. The header "Authorization:token |
The tests require access to a postgreSQL database named webmaker_testing
. Create it by running the command createdb webmaker_testing
, the test script will automatically create tables and populate them with data.
Run the tests with npm test
Run database migrations with the following command npm run migrate -- webmaker
Substitute 'webmaker' in the last command with whichever database name your api is using. It will apply all migration scripts in the migrations file in order.
A bulk api endpoint exists to enable the client to execute many actions on the user's project, pages, elements in a single HTTP request instead of many individual ones.
URL
/user/{user}/bulk
Method
POST
Authentication
The Authorization header should contain a valid OAuth token provided by id.webmaker.org
Authorization: token myoauth2tokenforwebmaker
Body
Post body should be valid JSON. It should contain a single attribute, actions
, an array of at least one, and at most 1000 individual actions to execute in serial.
Each action should contain three properties, type
, method
, and data
.
Type must be one of 'projects', 'pages', or 'elements'.
Method must be one of 'create', 'update' or 'remove'.
Data must contain attributes and values specific to the type and method of the action:
title
thumbnail
id
title
id
projectId
x
y
styles
{}
id
x
y
styles
{}
id
pageId
type
styles
{}
attributes
{}
id
styles
{}
attributes
{}
id
You can reference future id values using the following syntax: $1.id
, where the number following the dollar sign represents the index of the action, and the path following it is used to grab the id you're looking for. For example:
{
"actions": [
{
"type": "projects",
"method": "create",
"data": {
"title": "My Project"
}
},
{
"type": "pages",
"method": "create",
"data": {
"projectId": "$0.id",
"x": 0,
"y": 0
}
}
]
}
The Webmaker API uses id.webmaker.org to authenticate users and requests using Bearer tokens. Below is a sequence diagram describing how a create project request is handled for a first time user.