40ants-openrpc - A set of helpers to start JSON-RPC server based on https://40ants.com/openrpc/ library.
- Description: A set of helpers to start
JSON-RPC
server based on https://40ants.com/openrpc/ library. - Licence: Unlicense
- Author: Alexander Artemenko [email protected]
- Homepage: https://40ants.com/40ants-openrpc/
- Bug tracker: https://github.com/40ants/40ants-openrpc/issues
- Source control: GIT
- Depends on: 40ants-logging, 40ants-slynk, alexandria, cl+ssl, cl-json-web-tokens, clack, clack-cors, clack-prometheus, dexador, jsonrpc, lack-request, local-time, log4cl, log4cl-extras, openrpc-client, openrpc-server, serapeum, with-user-abort
You can install this library from Quicklisp, but you want to receive updates quickly, then install it from Ultralisp.org:
(ql-dist:install-dist "http://dist.ultralisp.org/"
:prompt nil)
(ql:quickload :40ants-openrpc)
This is a set of opionated helpers for starting Common Lisp OpenRPC
servers which uses:
Also, it can manage a multiple OpenRPC
servers in the one Lisp image.
The easiest way to start a server is to define one or more api methods using OpenRPC
library
and then call start
. This will bring API
on http://localhost:8000/ and it's spec will be available
as http://localhost:8000/openrpc.json
This system uses following environment variables to configure the server:
APP_PORT
andAPP_INTERFACE
are used instart-in-production
function to control on which port and interfaceAPI
should be started on.DEBUG
also used instart-in-production
function to control how verbose logging should be. If it is given then logging will be withDEBUG
level.CORS_ALLOWED_ORIGIN
andCORS_ALLOWED_HEADERS
are control howAPI
will respond withCORS
related headers. Learn more about used middleware inclack-cors
system documentation.
package 40ants-openrpc/client
macro 40ants-openrpc/client:generate-client
name url
package 40ants-openrpc/jwt
function 40ants-openrpc/jwt:decode
token
function 40ants-openrpc/jwt:issue-token
payload &key ttl
Encodes payload into a JWT
token.
If TTL
argument is given, it should be specified in seconds. After this number of seconds, token will become invalid.
macro 40ants-openrpc/jwt:with-session
((&REST BINDINGS) &KEY (REQUIRE T) (PROCESSORS '(("roles" . ENSURE-LIST-OF-KEYWORDS)))) &BODY BODY
macro 40ants-openrpc/jwt:with-test-token
(token) &body body
package 40ants-openrpc/server
function 40ants-openrpc/server:start
&key (port *default-port*) (api openrpc-server/api::default-api) (interface *default-interface*) (debug nil)
Starts Open RPC
API
server on given PORT
and INTERFACE
.
Also it configures logging and Slynk.
Slynk is started only if SLYNK
_PORT
env variable is set to some value.
You will find more details in the 40ants-slynk
system documentation.
function 40ants-openrpc/server:start-in-production
&key (api openrpc-server/api::default-api)
Entry point for API
webserver, started in the Docker or Kubernetes.
It works like a start
but blocks forever.
function 40ants-openrpc/server:stop
&key (port *default-port*) (interface *default-interface*)
Stops API
server running on given PORT
and INTERFACE
.