RESTrict Framework#
The RESTrict Framework is a different way to think about constructing Web applications. It defines a new paradigm, functional-declarative hybrid, resource-oriented development, a hybrid of declarative and functional programming. It is the hope that this new paradigm engenders a new mental model for Web applications, one that more naturally fits the hypertext as the engine of application state.
The blog example#
The “Hello, World!” of applications is a simple blogging site. Making this application with the RESTrict Framework takes three steps.
1. Declare the resources#
To declare your resources, you define .resource
or .resources
files that
contain the shape of the data for your resources, how they relate to one
another, and who can access the different actions on the resources.
Code subject to change
The RESTrict Framework is currently in its early design and development phase. The following code sample is subject to change at any time.
include <types/text>
include <security/password>
party Person {
name: Text(1,100)
email: unique Email
dnc {
<description> PasswordAccountDescription
}
}
role Writer {
author: assignment.person
active: assignment.assigned <= now() <= assignment.unassigned
dnc {
<previous:1> assignment: WriterAssignment
}
security {
accessors {
<entrypoint> list: request.actor.isAdmin
details: request.actor.isAdmin
}
}
}
interval WriterAssignment {
assigned: Timestamp
unassigned: optional Timestamp (>= assigned)
dnc {
<party:1> Person
<next:1> Writer
}
effects {
create {
transact create Writer { assignment: this }
}
}
security {
mutators {
create: request.actor.isAdmin
modify: {
unassigned: request.actor.isAdmin
}
}
accessors {
*: request.actor.isAdmin
}
}
}
moment Post {
title: Text(1,100)
published: optional Date
content: Markdown
dnc {
<role:1> author: Writer
<next:*> comments: page Comment
}
security {
mutators {
create: request.actor.roles |> filter(x | x is Writer) |> any(x | x.active)
modify: request.actor = author
delete: request.actor = author
}
accessors {
<entrypoint> list: published
details: *
}
}
}
moment Comment {
submitted: Timestamp
content: Markdown(p, ul, ol, li)
dnc {
<party:?> author: Person
<previous:1> post: Post
}
security {
accessors {
details: {
author: request.actor is defined
*: *
}
}
mutators {
delete: request.actor in [author, post.author]
modify: request.actor = author
create: *
}
}
}
2. Configure a persistent store#
Tell the RESTrict Framework how to connect to a persistent store.
restrict:
persistence:
resources:
_: postgresql://blogger@pwd@localhost/blog
3. Start the application#
Install and run the application using Python 3.11 or newer.
pip install --user restrict-framework
python -m restrict.framework --resources post.resources
Now, use the API#
Use REST, GraphQL, and WebSockets to interact with the API.