Liking cljdoc? Tell your friends :D

dk.simongray.micropub.server

The Micropub endpoint and the media endpoint as Ring handlers. They check the access token, read the request and pass it to your functions, which store the posts and the files.

The code follows the W3C Recommendation of 23 May 2017 at https://www.w3.org/TR/micropub/ and cites its sections. The handlers check access tokens with indieauth-clj, in the token store of a server in the same process or at the introspection endpoint of one elsewhere.

The Micropub endpoint and the media endpoint as Ring handlers. They
check the access token, read the request and pass it to your functions,
which store the posts and the files.

The code follows the W3C Recommendation of 23 May 2017 at
https://www.w3.org/TR/micropub/ and cites its sections. The handlers
check access tokens with indieauth-clj, in the token store of a server
in the same process or at the introspection endpoint of one elsewhere.
raw docstring

actionclj/s

(action request)
(action request opts)

The action in the Ring request of a POST, read within the :max-bytes of opts, or a map of the :error when the request isn't valid.

The action is a map of its :action, one of :create, :update, :delete and :undelete, and of:

  • the :type, :properties and :commands of a create, and the :files of a multipart create by property, as Ring's multipart middleware reads them
  • the :url of the others
  • the :replace, :add and :delete of an update

Every value is a vector, whatever the syntax, and the access token is left out.

The action in the Ring `request` of a POST, read within the :max-bytes
of `opts`, or a map of the :error when the request isn't valid.

The action is a map of its :action, one of :create, :update, :delete and
:undelete, and of:

- the :type, :properties and :commands of a create, and the :files of a
  multipart create by property, as Ring's multipart middleware reads
  them
- the :url of the others
- the :replace, :add and :delete of an update

Every value is a vector, whatever the syntax, and the access token is
left out.
sourceraw docstring

default-optionsclj/s

The defaults of the handlers' options:

  • :scopes, for each kind of request (:create, :update, :delete, :undelete, :media and :query), the scopes of which a token needs one. Micropub 5.4 names create, update and delete. An undelete also takes the undelete scope that micropub.rocks asks for, and an upload takes create, since clients seldom ask for media.
  • :insufficient-scope-status, 401 as in Micropub 3.8, where the living standard and RFC 6750 have 403
  • :max-bytes, 1 MB, the largest form or JSON body that the handlers read themselves

A token with the draft scope but none of the :create scopes may create and update drafts, as https://github.com/indieweb/micropub-extensions/issues/24 proposes.

The defaults of the handlers' options:

- :scopes, for each kind of request (:create, :update, :delete,
  :undelete, :media and :query), the scopes of which a token needs one.
  Micropub 5.4 names create, update and delete. An undelete also takes
  the undelete scope that micropub.rocks asks for, and an upload takes
  create, since clients seldom ask for media.
- :insufficient-scope-status, 401 as in Micropub 3.8, where the living
  standard and RFC 6750 have 403
- :max-bytes, 1 MB, the largest form or JSON body that the handlers read
  themselves

A token with the draft scope but none of the :create scopes may create
and update drafts, as
https://github.com/indieweb/micropub-extensions/issues/24 proposes.
sourceraw docstring

handlerclj/s

(handler opts)

A Ring handler for the Micropub endpoint, with the opts below.

Each function among the opts gets the action of a POST or the query of a GET, with the :token-info from indieauth-clj (the token's :me, :client-id and :scope) and the :ring-request. The access token in the Ring request is hidden with wary-fetch's secret/hide, so it doesn't show when you print or log the request.

  • :me-pred, a predicate of the :me of a token, e.g. a set of your profile URLs
  • :tokens, the token store of an IndieAuth server in the same process, or the :introspection-endpoint and :resource-token of one elsewhere
  • :create!, a function of a create that returns the :url of the new post, with :status 202 if the post goes live later
  • :source, a function of a map with a :url that returns the entry at that URL, or nil
  • :update!, a function of an update with the :entry that apply-update made from the entry that :source returned. It returns nil, or the :url of a post that moved.
  • :delete! and :undelete!, functions of a delete or an undelete that return nil, or the :url of a post that moved
  • :upload!, a function of a file in a multipart create, as Ring's multipart middleware has it, that returns the file's URL
  • :config, a map for q=config, or a function of the query that returns one. Its :syndicate-to answers q=syndicate-to.
  • :media-endpoint, the URL of the media endpoint, for q=config
  • :queries, a map of other queries by name, e.g. :category, to functions of the query that return the answer
  • the :scopes, :insufficient-scope-status and :max-bytes of default-options, and the options of indieauth-clj's token checks

Any function can return a map of the :error instead, a problem as problem-response takes it, or in ClojureScript a promise. An action without its function gets invalid_request, and an update needs :source too (Micropub 2.1.3).

The handler reads form and JSON bodies itself or takes what middleware has read. Multipart bodies need the server's multipart middleware, e.g. Ring's, which keeps large files out of memory. The handler takes the arguments of both a synchronous and an asynchronous Ring handler.

A Ring handler for the Micropub endpoint, with the `opts` below.

Each function among the `opts` gets the action of a POST or the query of
a GET, with the :token-info from indieauth-clj (the token's :me,
:client-id and :scope) and the :ring-request. The access token in the
Ring request is hidden with wary-fetch's secret/hide, so it doesn't show
when you print or log the request.

- :me-pred, a predicate of the :me of a token, e.g. a set of your
  profile URLs
- :tokens, the token store of an IndieAuth server in the same process,
  or the :introspection-endpoint and :resource-token of one elsewhere
- :create!, a function of a create that returns the :url of the new
  post, with :status 202 if the post goes live later
- :source, a function of a map with a :url that returns the entry at
  that URL, or nil
- :update!, a function of an update with the :entry that apply-update
  made from the entry that :source returned. It returns nil, or the :url
  of a post that moved.
- :delete! and :undelete!, functions of a delete or an undelete that
  return nil, or the :url of a post that moved
- :upload!, a function of a file in a multipart create, as Ring's
  multipart middleware has it, that returns the file's URL
- :config, a map for q=config, or a function of the query that returns
  one. Its :syndicate-to answers q=syndicate-to.
- :media-endpoint, the URL of the media endpoint, for q=config
- :queries, a map of other queries by name, e.g. :category, to functions
  of the query that return the answer
- the :scopes, :insufficient-scope-status and :max-bytes of
  default-options, and the options of indieauth-clj's token checks

Any function can return a map of the :error instead, a problem as
problem-response takes it, or in ClojureScript a promise. An action
without its function gets invalid_request, and an update needs :source
too (Micropub 2.1.3).

The handler reads form and JSON bodies itself or takes what middleware
has read. Multipart bodies need the server's multipart middleware, e.g.
Ring's, which keeps large files out of memory. The handler takes the
arguments of both a synchronous and an asynchronous Ring handler.
sourceraw docstring

media-handlerclj/s

(media-handler opts)

A Ring handler for the media endpoint, with the opts of handler.

It needs the :me-pred, the :tokens or :introspection-endpoint, and the :upload!. The file is the part named file of a multipart body, which the server's multipart middleware reads, e.g. Ring's. The :upload! gets the file with the :token-info and the :ring-request, with its token hidden as in handler, and returns its URL or a map of the :error. The handler takes the arguments of both a synchronous and an asynchronous Ring handler.

A Ring handler for the media endpoint, with the `opts` of handler.

It needs the :me-pred, the :tokens or :introspection-endpoint, and the
:upload!. The file is the part named file of a multipart body, which
the server's multipart middleware reads, e.g. Ring's. The :upload! gets
the file with the :token-info and the :ring-request, with its token
hidden as in handler, and returns its URL or a map of the :error. The handler takes the arguments of both a
synchronous and an asynchronous Ring handler.
sourceraw docstring

problem-responseclj/s

(problem-response {:keys [status code reason scope challenge] :as problem})

The Ring response to the problem, a map of a Micropub error :code and its :reason (Micropub 3.8).

The status is the code's unless the problem has a :status. A :scope names the scope that the request needs, and a :challenge becomes the WWW-Authenticate header of RFC 6750.

The Ring response to the `problem`, a map of a Micropub error :code and
its :reason (Micropub 3.8).

The status is the code's unless the problem has a :status. A :scope
names the scope that the request needs, and a :challenge becomes the
WWW-Authenticate header of RFC 6750.
sourceraw docstring

queryclj/s

(query request)

The query in the Ring request of a GET: a map of its :q (e.g. :source) and its other parameters by name, such as the :url and :properties of a source query. The access token is left out.

The query in the Ring `request` of a GET: a map of its :q (e.g. :source)
and its other parameters by name, such as the :url and :properties of a
source query. The access token is left out.
sourceraw docstring

statusesclj/s

The HTTP status of each error code of Micropub 3.8.

The HTTP status of each error code of Micropub 3.8.
sourceraw docstring

cljdoc builds & hosts documentation for Clojure/Script libraries

Keyboard shortcuts
Ctrl+kJump to recent docs
←Move to previous article
→Move to next article
Ctrl+/Jump to the search field
× close