Identifier generator based on FastAPI and erdi8
This software intentionally has no license attached. It does not need to comply to the GPL-3.0 license of erdi8
as the erdi8
copyright holder and the author of fasterid
are the same person. Please get in touch if you plan to use this in a commercial setting.
$ pip install -r requirements.txt
$ cat fasterid.env
ERDI8_STRIDE = "453459956896834"
ERDI8_START = "b222222222"
ERDI8_SAFE = True
FASTERID_FILENAME = "last-id.txt"
FASTERID_PROPERTY = "https://schema.org/identifier"
FASTERID_DEFAULT_PREFIX = "https://example.org/"
FASTERID_MAX_NUM = 50
FASTERID_ALWAYS_RDF = False
FASTERID_MAX_PREFIX_LEN = 100
$ uvicorn fasterid:app
INFO: Started server process [116821]
INFO: Waiting for application startup.
INFO: Application startup complete.
INFO: Uvicorn running on http://127.0.0.1:8000 (Press CTRL+C to quit)
$ curl http://127.0.0.1:8000 -X POST
{"@id": "k7zydqrp64"}
# Call http://127.0.0.1:8000/docs for API info in a browser
Test
# From a different terminal
$ while true; do printf "$(curl -X POST http://127.0.0.1:8000)\n" >> ids; done
# After some seconds stop with: CTRL+C
$ head ids
{"@id":"ptzxm3mz85"}
{"@id":"tfzwsfhbb6"}
{"@id":"y2zvyscnd7"}
{"@id":"cnzv657yg8"}
{"@id":"h8ztch49j9"}
{"@id":"mvzsjtymmb"}
{"@id":"rgzrr6txpc"}
{"@id":"w3zqxjq8rd"}
{"@id":"zpzq4wkktf"}
{"@id":"f9zpb8fwwg"}
The service accepts also two optional parameters: prefix
and number
. The first can be used for creating individual identifiers with a prefix, the second is creating a batch with a certain number of ids. If application/ld+json
is provided in the accept header the prefix
or the FASTERID_ID_DEFAULT_PREFIX
environment setting to create valid RDF. In that case, the generated erdi8 identifier MUST form a valid absolute IRI together with the provided prefix
or FASTERID_ID_DEFAULT_PREFIX
. The number
and prefix
parameters can be configured respecting max batch size and prefix length.
$ curl -X POST http://127.0.0.1:8000 \
--data '{"number": 5, "prefix": "https://example.com/"}' \
-H "content-type: application/json" -H "accept: application/ld+json" | jq
[
{
"@id": "https://example.com/t7t9vt26f4",
"https://schema.org/identifier": "t7t9vt26f4"
},
{
"@id": "https://example.com/xtt935whh5",
"https://schema.org/identifier": "xtt935whh5"
},
{
"@id": "https://example.com/cft88hrtk6",
"https://schema.org/identifier": "cft88hrtk6"
},
{
"@id": "https://example.com/h2t7fvn5n7",
"https://schema.org/identifier": "h2t7fvn5n7"
},
{
"@id": "https://example.com/mnt6n7hgq8",
"https://schema.org/identifier": "mnt6n7hgq8"
}
]
docker build -t fasterid .
docker run -d -p 80:80 fasterid
# OR
docker run -d -p 80:80 -e FASTERID_DEFAULT_PREFIX="" fasterid
# OR
docker run -d -p 80:80 -e FASTERID_DEFAULT_PREFIX="https://w3id.org/myspace/" -e FASTERID_ALWAYS_RDF="True" fasterid
# OR
docker run --log-driver=awslogs -d -p 80:80 -e FASTERID_DEFAULT_PREFIX="" fasterid
# OR
docker run --log-driver=awslogs -d -v /home/ec2-user/latest-id.txt:/fasterid-0.1.2/last-id.txt -e FASTERID_DEFAULT_PREFIX="" -p 80:80 fasterid