An erlang diversity api that serves files and settings on the fly.
Diversity-api requires Erlang/OTP R17 which can be downloaded here:
https://www.erlang-solutions.com/downloads/download-erlang-otp
Before compiling you need to configure where the git repos should be cloned to and
what port to use for the api server. This is currently done in the rel/sys.config
file:
repo_dir
Where all diversity components will be checked out to.nodes
List of nodes where updates and registers will be called on. Empty list if no other nodes exists.port
Which port the node will be listening to.
[{
divapi, [{repo_dir, "path/to/your/directory"},
{nodes, []},
{port, 8181},
%% Optional
stage, [
{fallback, <<"api.diversity.io">>},
{staging_regexp, <<"\\w*stage.*">>}
]}]
}].
To configure or change configuration after building the release, the sys.config used by the release are located in
_rel/divapi_release/releases/1/sys.config
.
make
- Fetches dependencies, compiles and builds a release in _rel/divapi_release/
There is a way to test and develop components locally and use the same endpoints. You need to set a fallback url e.g. api.diversity.io and optional a regexp or hardcoded staging env.
stage, [
{fallback, <<"api.diversity.io">>},
{staging_regexp, <<"\\w*stage.*">>}
]}
If the staging url is example.com.foostage.company.org
, it will with the regexp in example
split it to example.com
and foostage.company.org
. Then later split the later part and
use foostage
as a subfolder on repo_dir
setting.
./_rel/divapi_release/bin/divapi_release start
- start the server./_rel/divapi_release/bin/divapi_release stop
- stop the server./_rel/divapi_release/bin/divapi_release console
- start the server with a console
GET /minify-js?my-component=0.0.3&my-component2=1.0.0
Response:
All script files minified and concatenated to one blob.
*
- Will expand to the latest tagX
- Will expand into latest tag in given majorX.Y
- Will expand into latest tag in given major and minor
GET /components/
Response:
[{"version":"0.0.4","title":"My First Component,"name":"my-component1","description":"A component that will do stuff"},
{"version":"1.0.0","title":"My Second Component","name":"my-component2","description":"A component that will do even more stuff"}]
GET /components/my-component1/
Response:
["0.0.1", "0.0.2", "0.0.3", "0.0.4"]
GET /components/?grouping=sidebar
Response:
["my-component2"]
GET /components/my-component2/1.0.0/
Response:
{
"name": "my-component2",
"title": "My Second Component",
"description": "A component that will do even more stuff",
"version": "1.0.0",
"angular": "myComponent2",
"template": "component.mustache.html",
"script": [
"scripts.min.js"
],
"settings": {
"type": "object",
"properties": {
"classes": {
"type": "array",
"items": {
"type": "string"
}
}
}
},
"dependencies": {
"my-component1": "^0.0.1",
}
}
GET /components/my-component2/0.1/
GET /components/my-component2/*/
GET /components/my-component2/1.0.0/css?foo=bar
Response: A CSS file
GET /components/my-components2/1.0.0/settings
Response:
{
"settings": {
"type": "object",
"properties": {
"classes": {
"type": "array",
"items": {
"type": "string"
}
}
}
}
}
GET /components/my-component/0.0.1/settingsForm
Response:
{}
GET /components/<component>/1.2.3/thumbnail
Response: Image data
GET /components/my-component2/1.0.0/files/script.min.js
Response: The requested files from the component
All the version selection methods can be used to get settings, settingsForm and files from the selected version.
curl -X POST -d repo_url=https://github.com/foobar/foo.git example.com/components/foo/register
curl -X POST example.com/components/foo/update