Serverless Server lets you upload and run lambdas without much hassle about running and maintaining the server itself. It communicates through REST, so it is easy to use and extend. Applications can be build on top of it.
Prerequisites:
- Docker
- Java 7 or higher
- Bitcoin-Qt
The Server runs on Spring, which needs to be imported.
additional Prerequisites:
- Clone the repo:
https://github.com/serverlessserver/standard.git
- Import it into Intellij/Eclipse etc.
- Import Modules with Maven, given in
pom.xml
. - Run Bitcoin-Qt in
-testnet
mode - Run.
It works on Unix-like Systems. Windows should work too but no guarantee.
TODO make and link jar
- Download JAR.
- Run jar.
The Server listens to http://localhost:8080/
, so you can try things out.
If you have a lambda, you can upload it and pay for it by sending a POST
request:
http://localhost:8080/lambdas/pay
Headers:
Content-Type: application/json
Body:
{
"name":"yourlambdaname",
"runtimeAttributes":{
"language":"Python3",
"libraries":[],
"code":"print(\"Hello world\")"
}
}
You will receive a Bitcoin URI, which you should open in your browser to receive a payment request. So when you open Bitcoin URI
in browser, than your bitcoin client receives payment request which you need to confirm in order to get JSON Webtoken which you will use
to access your uploaded lambda. When you have done the confirmation of payment request than you will receive payment acknowledgement,
where will be your JSON Webtoken. You need to save it for future usage of uploaded and paid function.
Payment is provided by using two protocols BIP70 and BIP72.
Note that payments are provided only for virtual bitcoins in test bitcoin's network! However it could be easily changed for real payments by setting MainNetParam
in constructor of PaymentServer.java.
If you want to update your lambda send a PUT
to:
http://localhost:8080/lambdas/yourlambdaname
Headers:
Content-Type: application/json
Authorization: Bearer tokenyougotwhenyouuploadedyourfunction
Body:
{
"name":"yourlambdaname",
"runtimeAttributes":{
"language":"Python3",
"libraries":[],
"code":"print(\"Bye world\")"
}
}
You will receive a JSON Webtoken, which you should keep, because you'll need this to access your updated lambda. The old JWT is not valid anymore.
If you want to check what you've uploaded, send a GET
to:
http://localhost:8080/lambdas/yourlambdaname
Headers:
Content-Type: application/json
Authorization: Bearer token
This will send you your lambda configuration.
If you want to execute your lambda, send POST
to:
http://localhost:8080/lambdas/yourlambdaname/execute
Headers:
Content-Type: application/json
Authorization: Bearer token
Body:
{
"times":"1",
"parameters":[]
}
If you want to generate a Subtoken e.g. for other apps to use (= only execute) the lambda, you can send a GET
with an expirydate to:
http://localhost:8080/lambdas/panda/token?expiryDate=yourexpirydate
Content-Type: application/json
Authorization: Bearer token
Note that subtokens can only execute and not upload/etc. So keep your mastertoken (token you get when you upload or update) to yourself to maintain your function and only give subtokens to customers.
If you want to delete your lambda, send a DEL
to:
http://localhost:8080/lambdas/yourlambdaname
Headers:
Content-Type: application/json
Authorization: Bearer token
More examples can be found under /src/testjava/edu/teco/serverless/
and also you can check out the documentation
and concepts.