Tutorial¶
Get started with Pyjoyment.
A quick example-driven introduction to the wonders of Pyjoyment.Lite.
Almost everything you’ll learn here also applies to full Pyjoyment
applications.
This is only the first of the guides. Other guides delve deeper into topics
like growing a Pyjoyment.Lite prototype into a
well-structured Pyjoyment application, routing,
rendering and more. It is highly encouraged that readers
continue on to the remaining guides after reading this one.
Hello World¶
A simple Hello World application can look like this. A few functions are
imported when you import everything from Pyjoyment.Lite, turning your
script into a full featured web application.
#!/usr/bin/env python
from Pyjoyment.Lite import *
@get('/')
def index(c):
c.render(text='Hello World!')
app.start()
With Pyjoyment.Command.Author.generate.lite_app there is also a helper
command to generate a small example application.
$ pyjo generate lite-app myapp.py
Commands¶
Many different commands of Pyjoyment.Commands are automatically
available from the command line. CGI, WSGI and ASGI environments can even be
detected and will usually just work without commands.
$ ./myapp.py daemon
Web application available at http://127.0.0.1:3000
$ ./myapp.py daemon -l http://*:8080
Web application available at http://127.0.0.1:8080
$ ./myapp.py cgi
...CGI output...
$ ./myapp.py get /
Hello World!
$ ./myapp.py
...List of available commands (or automatically detected environment)...
A call to start() (app.start()), which
starts the command system, should be the last expression in your
application, because its return value can be significant.
# Use sys.argv to pick a command
app.start()
# Start the "daemon" command
app.start('daemon', '-l', 'http://*:8080')
Reloading¶
Your application will automatically reload itself if you start it with the
Pyjo.Server.Reload development web server, so you don’t have to
restart the server after every change.
$ pyjo-reload ./myapp.py
Web application available at http://127.0.0.1:3000
For more information about how to deploy your application see also the deployment in the cookbook.
Routes¶
Routes are basically just fancy paths that can contain different kinds of
placeholders and usually lead to an action, if they match the path part of
the request URL. The first argument passed to all actions (c) is a
Pyjoyment.Controller object, containing both the HTTP request and
response. A route is a decorator of its action, which returns the route.
from Pyjoyment.Lite import *
# Route leading to an action that renders some text
@get('/foo')
def foo(c):
c.render(text='Hello World!')
app.start()
Response content is often generated by actions with
render(), but more about that
later.
GET/POST parameters¶
All GET and POST parameters sent with the request are accessible via
param().
from Pyjoyment.Lite import *
# /foo?user=sri
@get('/foo')
def foo(c):
user = c.param('user')
c.render(text=f'Hello {user}.')
app.start()
Stash and templates¶
The stash() is used to pass
data to templates, which can be inlined in the DATA section, the
docstring of the script after a line __DATA__. A few stash values like
template, text and data are reserved and will be used by
render() to decide how a
response should be generated.
"""
__DATA__
@@ magic.html.ep
The magic numbers are <%= one %> and <%= two %>.
"""
from Pyjoyment.Lite import *
# Route leading to an action that renders a template
@get('/foo')
def foo(c):
c.stash(one=23)
c.render(template='magic', two=24)
app.start()
The code of a template is Python, and the values of the stash are its
variables. For more information about templates see also
Pyjo.Template.
HTTP¶
req and
res give you full access to
all HTTP features and information.
from Pyjoyment.Lite import *
# Access request information
@get('/agent')
def agent(c):
host = c.req.url.to_abs().host
ua = c.req.headers.user_agent
c.render(text=f'Request by {ua} reached {host}.')
# Echo the request body and send custom header with response
@post('/echo')
def echo(c):
c.res.headers.header('X-Bender', 'Bite my shiny metal ass!')
c.render(data=c.req.body)
app.start()
You can test the more advanced examples right from the command line with
Pyjoyment.Command.get.
$ ./myapp.py get -v -M POST -c 'test' /echo
JSON¶
JSON is the most commonly used data-interchange format for web services.
Pyjoyment loves JSON and comes with Pyjo.JSON built right in,
which is accessible through json() as well as
the reserved stash value json.
from Pyjoyment.Lite import *
# Modify the received JSON document and return it
@put('/reverse')
def reverse(c):
document = c.req.json()
document['message'] = document['message'][::-1]
c.render(json=document)
app.start()
You can send JSON documents from the command line with
Pyjoyment.Command.get.
$ ./myapp.py get -M PUT -c '{"message":"Hello Pyjo!"}' /reverse
Built-in exception and not_found pages¶
During development you will encounter these pages whenever you make a mistake, they are gorgeous and contain a lot of valuable information that will aid you in debugging your application.
from Pyjoyment.Lite import *
# Not found (404)
@get('/missing')
def missing(c):
c.reply.not_found()
# Exception (500)
@get('/dies')
def dies(c):
raise Exception('Intentional error')
app.start()
You can even use CSS selectors with Pyjoyment.Command.get to extract
only the information you’re actually interested in.
$ ./myapp.py get /dies '#error'
And don’t worry about revealing too much information on these pages, they are only available during development, and will be replaced automatically with pages that don’t reveal any sensitive information in a production environment.
Route names¶
All routes can have a name associated with them, this allows automatic
template detection and backreferencing with
url_for(), on which many
methods and helpers like link_to of
Pyjoyment.Plugin.TagHelpers rely.
"""
__DATA__
@@ index.html.ep
<%= link_to('Hello', 'hello') %>.
<%= link_to('Reload', 'index') %>.
@@ hello.html.ep
Hello World!
"""
from Pyjoyment.Lite import *
# Render the template "index.html.ep"
@get('/', 'index')
def index(c):
c.render()
# Render the template "hello.html.ep"
get('/hello')
app.start()
Nameless routes get an automatically generated one assigned that is simply equal to the route itself without non-word characters.
Layouts¶
Templates can have layouts too, you just select one with the helper
layout of Pyjoyment.Plugin.DefaultHelpers and place the result of
the current template with the helper content.
"""
__DATA__
@@ with_layout.html.ep
% title('Green')
% layout('green')
Hello World!
@@ layouts/green.html.ep
<!DOCTYPE html>
<html>
<head><title><%= c.title() %></title></head>
<body><%= content() %></body>
</html>
"""
from Pyjoyment.Lite import *
get('/with_layout')
app.start()
The stash or helpers like title can be used to pass additional data to the
layout. A value of the stash hides the helper of its name in a template, as
Python has one namespace for both, so the layout calls the helper title,
which keeps its value in the stash, as a method of c.
Blocks¶
Template blocks can be used like normal Python functions and are always
delimited by the begin and end keywords, they are the foundation for
many helpers. The arguments of a block are args.
"""
__DATA__
@@ block.html.ep
% link = begin
% url, name = args
Try <%= link_to(url, begin %><%= name %><% end) %>.
% end
<!DOCTYPE html>
<html>
<head><title>Sebastians frameworks</title></head>
<body>
%= link('https://mojolicious.org', 'Mojolicious')
%= link('https://pyjoyment.readthedocs.io', 'Pyjoyment')
</body>
</html>
"""
from Pyjoyment.Lite import *
get('/with_block', 'block')
app.start()
Helpers¶
Helpers are little functions you can create with the function helper of
Pyjoyment.Lite and reuse throughout your whole application, from
actions to templates.
"""
__DATA__
@@ secret.html.ep
We know who you are <%= whois() %>.
"""
from Pyjoyment.Lite import *
# A helper to identify visitors
@helper('whois')
def whois(c):
agent = c.req.headers.user_agent or 'Anonymous'
ip = c.tx.remote_address
return f'{agent} ({ip})'
# Use helper in action and template
@get('/secret')
def secret(c):
user = c.whois()
c.app.log.debug(f'Request from {user}')
app.start()
A list of all built-in ones can be found in
Pyjoyment.Plugin.DefaultHelpers and Pyjoyment.Plugin.TagHelpers.
Plugins¶
Plugins are application extensions that help with code sharing and
organization. You can load a plugin with the function plugin of
Pyjoyment.Lite, which can omit the Pyjoyment.Plugin. part of the
name, and optionally provide configuration for the plugin.
from Pyjoyment.Lite import *
plugin('Config', file='/etc/myapp.conf', default={'foo': 'bar'})
# Return configured foo value, or default if no configuration file
@get('/foo')
def foo(c):
foo = c.app.config('foo')
c.render(json={'foo': foo})
app.start()
Pyjoyment.Plugin.Config is a built-in plugin which can populate
config() using a config file. Plugins can also set
up routes, hooks, handlers, or even load other plugins. A list of built-in
plugins can be found at Pyjoyment.Plugins.
Placeholders¶
Route placeholders allow capturing parts of a request path until a / or
. separator occurs, similar to the regular expression ([^/.]+).
Results are accessible via
stash() and
param().
from Pyjoyment.Lite import *
# /foo/test
# /foo/test123
@get('/foo/:bar')
def foo(c):
bar = c.stash('bar')
c.render(text=f'Our :bar placeholder matched {bar}')
# /testsomething/foo
# /test123something/foo
@get('/<:bar>something/foo')
def something(c):
bar = c.param('bar')
c.render(text=f'Our :bar placeholder matched {bar}')
app.start()
To separate them from the surrounding text, you can surround your
placeholders with < and >, which also makes the colon prefix
optional.
Relaxed Placeholders¶
Relaxed placeholders allow matching of everything until a / occurs,
similar to the regular expression ([^/]+).
"""
__DATA__
@@ groovy.html.ep
Your name is <%= you %>.
"""
from Pyjoyment.Lite import *
# /hello/test
# /hello/test.html
get('/hello/#you', 'groovy')
app.start()
Wildcard placeholders¶
Wildcard placeholders allow matching absolutely everything, including /
and ., similar to the regular expression (.+).
"""
__DATA__
@@ groovy.html.ep
Your name is <%= you %>.
"""
from Pyjoyment.Lite import *
# /hello/test
# /hello/test123
# /hello/test.123/test/123
get('/hello/*you', 'groovy')
app.start()
HTTP methods¶
Routes can be restricted to specific request methods with different functions
like get and any of Pyjoyment.Lite.
from Pyjoyment.Lite import *
# GET /hello
@get('/hello')
def hello(c):
c.render(text='Hello World!')
# PUT /hello
@put('/hello')
def upload(c):
size = len(c.req.body)
c.render(text=f'You uploaded {size} bytes to /hello.')
# GET|POST|PATCH /bye
@any(['GET', 'POST', 'PATCH'], '/bye')
def bye(c):
c.render(text='Bye World!')
# * /whatever
@any('/whatever')
def whatever(c):
method = c.req.method
c.render(text=f'You called /whatever with {method}.')
app.start()
Optional placeholders¶
All placeholders require a value, but by assigning them default values you can make capturing optional.
"""
__DATA__
@@ groovy.txt.ep
My name is <%= name %> and it is <%= day %>.
"""
from Pyjoyment.Lite import *
# /hello
# /hello/Sara
@get('/hello/:name', {'name': 'Sebastian', 'day': 'Monday'})
def hello(c):
c.render(template='groovy', format='txt')
app.start()
Default values that don’t belong to a placeholder simply get merged into the stash all the time.
Restrictive placeholders¶
A very easy way to make placeholders more restrictive are alternatives, you just make a list of possible values, as a keyword argument with the name of the placeholder.
from Pyjoyment.Lite import *
# /test
# /123
@any('/:foo', foo=['test', '123'])
def foo(c):
foo = c.param('foo')
c.render(text=f'Our :foo placeholder matched {foo}')
app.start()
All placeholders get compiled to a regular expression internally, this
process can also be customized. Just make sure not to use ^ and $, or
capturing groups (...), non-capturing groups (?:...) are fine though.
from Pyjoyment.Lite import *
import re
# /1
# /123
@any('/:bar', bar=re.compile(r'\d+'))
def bar(c):
bar = c.param('bar')
c.render(text=f'Our :bar placeholder matched {bar}')
app.start()
You can take a closer look at all the generated regular expressions with the
command Pyjoyment.Command.routes.
$ ./myapp.py routes -v
Under¶
Authentication and code shared between multiple routes can be realized easily
with routes generated by the function under of Pyjoyment.Lite. All
following routes are only evaluated if the callback returned a true value.
"""
__DATA__
@@ denied.html.ep
You are not Bender, permission denied.
@@ index.html.ep
Hi Bender.
"""
from Pyjoyment.Lite import *
# Authenticate based on name parameter
@under
def authenticate(c):
# Authenticated
name = c.param('name') or ''
if name == 'Bender':
return True
# Not authenticated
c.render(template='denied')
return None
# Only reached when authenticated
get('/', 'index')
app.start()
Prefixing multiple routes is another good use for it.
from Pyjoyment.Lite import *
# /foo
under('/foo')
# /foo/bar
get('/bar', {'text': 'foo bar'})
# /foo/baz
get('/baz', {'text': 'foo baz'})
# / (reset)
under('/', {'msg': 'whatever'})
# /bar
get('/bar', {'inline': '<%= msg %> works'})
app.start()
You can also group related routes with the function group of
Pyjoyment.Lite, whose with block allows nesting of routes generated
with under.
from Pyjoyment.Lite import *
# Global logic shared by all routes
@under
def bender(c):
if c.req.headers.header('X-Bender'):
return True
c.render(text="You're not Bender.")
return None
# Admin section
with group():
# Local logic shared only by routes in this group
@under('/admin')
def admin(c):
if c.req.headers.header('X-Awesome'):
return True
c.render(text="You're not awesome enough.")
return None
# GET /admin/dashboard
get('/dashboard', {'text': 'Nothing to see here yet.'})
# GET /welcome
get('/welcome', {'text': 'Hi Bender.'})
app.start()
Formats¶
Formats can be automatically detected from file extensions like .html,
they are used to find the right template and generate the correct
Content-Type header. Use a restrictive placeholder to declare the
possible values.
"""
__DATA__
@@ detected.html.ep
<!DOCTYPE html>
<html>
<head><title>Detected</title></head>
<body>HTML was detected.</body>
</html>
@@ detected.txt.ep
TXT was detected.
"""
from Pyjoyment.Lite import *
# /detection.html
# /detection.txt
@get('/detection', format=['html', 'txt'])
def detection(c):
c.render(template='detected')
app.start()
And just like with placeholders you can use a default value to make the format optional.
from Pyjoyment.Lite import *
# /hello
# /hello.json
# /hello.txt
@get('/hello', {'format': 'txt'}, format=['json', 'txt'])
def hello(c):
if c.stash('format') == 'json':
return c.render(json={'hello': 'world'})
c.render(text='hello world')
app.start()
The default format is html and the renderer will fall back to when
necessary.
Content negotiation¶
For resources with different representations and that require truly RESTful
content negotiation you can also use the helper respond_to of
Pyjoyment.Plugin.DefaultHelpers.
from Pyjoyment.Lite import *
# /hello (Accept: application/json)
# /hello (Accept: application/xml)
# /hello.json
# /hello.xml
# /hello?_format=json
# /hello?_format=xml
@get('/hello', {'format': None}, format=['json', 'xml'])
def hello(c):
c.respond_to(
json={'json': {'hello': 'world'}},
xml={'text': '<hello>world</hello>'},
any={'data': b'', 'status': 204},
)
app.start()
MIME type mappings can be extended or changed easily with
types.
app.types.type('rdf', 'application/rdf+xml')
Static files¶
Similar to templates, but with only a single file extension and optional
Base64 encoding, static files can be inlined in the DATA section and are
served automatically.
"""
__DATA__
@@ something.js
alert('hello!');
@@ test.txt (base64)
dGVzdCAxMjMKbGFsYWxh
"""
from Pyjoyment.Lite import *
app.start()
External static files are not limited to a single file extension and will be
served automatically from a public directory if it exists.
$ mkdir public
$ mv something.js public/something.js
$ mv pyjoyment.tar.gz public/pyjoyment.tar.gz
Both have a higher precedence than routes for GET and HEAD requests.
Content negotiation with Range, If-None-Match and
If-Modified-Since headers is supported as well and can be tested very
easily with Pyjoyment.Command.get.
$ ./myapp.py get /something.js -v -H 'Range: bytes=2-4'
External templates¶
External templates will be searched by the renderer in a templates
directory if it exists.
$ mkdir -p templates/foo
$ echo 'Hello World!' > templates/foo/bar.html.ep
They have a higher precedence than templates in the DATA section.
from Pyjoyment.Lite import *
# Render template "templates/foo/bar.html.ep"
@any('/external')
def external(c):
c.render(template='foo/bar')
app.start()
Home¶
You can use home to interact with the directory
your application considers its home. This is the directory it will search for
public and templates directories, but you can use it to store all
sorts of application specific data.
$ mkdir cache
$ echo 'Hello World!' > cache/hello.txt
There are many useful methods Pyjo.Home inherits from
Pyjo.File, like child() and
slurp(), that will help you keep your application
portable across many different operating systems.
from Pyjoyment.Lite import *
# Load message into memory
hello = app.home.child('cache', 'hello.txt').slurp('UTF-8')
# Display message
@get('/')
def index(c):
c.render(text=hello)
app.start()
You can also introspect your application from the command line with
Pyjoyment.Command.eval.
$ ./myapp.py eval -v 'app.home'
Conditions¶
Conditions such as agent and host from
Pyjoyment.Plugin.HeaderCondition allow even more powerful route
constructs, with requires().
from Pyjoyment.Lite import *
import re
# Firefox
@get('/foo').requires(agent=re.compile(r'Firefox'))
def firefox(c):
c.render(text='Congratulations, you are using a cool browser.')
# Internet Explorer
@get('/foo').requires(agent=re.compile(r'Internet Explorer'))
def internet_explorer(c):
c.render(text='Dude, you really need to upgrade to Firefox.')
# http://mojolicious.org/bar
@get('/bar').requires(host='mojolicious.org')
def bar(c):
c.render(text='Hello Mojolicious.')
app.start()
Sessions¶
Cookie-based sessions just work out of the box, as soon as you start using
them through the helper session of Pyjoyment.Plugin.DefaultHelpers.
Just be aware that all session data gets serialized with Pyjo.JSON and
stored client-side, with a cryptographic signature to prevent tampering.
"""
__DATA__
@@ counter.html.ep
Counter: <%= session('counter') %>
"""
from Pyjoyment.Lite import *
# Access session data in action and template
@get('/counter')
def counter(c):
session = c.session()
session['counter'] = session.get('counter', 0) + 1
app.start()
Note that you should use custom secrets to
make signed cookies really tamper resistant.
app.secrets = ['My secret passphrase here']
File uploads¶
All files uploaded via multipart/form-data request are automatically
available as Pyjo.Upload objects from
param(). And you don’t have to
worry about memory usage, because all files above 250KiB will be
automatically streamed into a temporary file. To build HTML forms more
efficiently, you can also use tag helpers like form_for of
Pyjoyment.Plugin.TagHelpers, whose attributes follow its block.
"""
__DATA__
@@ form.html.ep
<!DOCTYPE html>
<html>
<head><title>Upload</title></head>
<body>
%= form_for('upload', begin
%= file_field('example')
%= submit_button('Upload')
% end, enctype='multipart/form-data')
</body>
</html>
"""
from Pyjoyment.Lite import *
# Upload form in DATA section
get('/', 'form')
# Multipart upload handler
@post('/upload')
def upload(c):
# Check file size
if c.req.is_limit_exceeded:
return c.render(text='File is too big.', status=200)
# Process uploaded file
if not (example := c.param('example')):
return c.redirect_to('form')
size = example.size
name = example.filename
c.render(text=f'Thanks for uploading {size} byte file {name}.')
app.start()
To protect you from excessively large files there is also a limit of 16MiB by
default, which you can tweak with the attribute
max_request_size.
# Increase limit to 1GiB
app.max_request_size = 1073741824
User agent¶
With Pyjo.UserAgent, which is available through the helper ua of
Pyjoyment.Plugin.DefaultHelpers, there’s a full featured HTTP and
WebSocket user agent built right in. Especially in combination with
Pyjo.JSON and Pyjo.DOM this can be a very powerful tool.
import Pyjo.Promise
from Pyjoyment.Lite import *
# Non-blocking with async and await
@get('/headers')
async def headers(c):
url = c.param('url') or 'https://github.com/pyjoyment/Pyjoyment'
tx = await c.ua().get_p(url)
c.render(json=tx.result.dom().find('h1, h2, h3').map('text').to_list())
# Non-blocking with a callback
@get('/title')
def title(c):
c.ua().get('https://github.com/mojolicious/mojo', lambda ua, tx: c.render(text=tx.result.dom().at('title').text))
# Concurrent non-blocking
@get('/titles')
def titles(c):
mojo = c.ua().get_p('https://github.com/mojolicious/mojo')
pyjo = c.ua().get_p('https://github.com/pyjoyment/Pyjoyment')
Pyjo.Promise.all(mojo, pyjo).then(
lambda mojo, pyjo: c.render(
json={
'mojo': mojo[0].result.dom().at('title').text,
'pyjo': pyjo[0].result.dom().at('title').text,
}
)
).wait()
app.start()
An action is an async function too, which can await a promise of the
user agent. A blocking request, without a callback, does not work in an
action of a server that runs on the asyncio event loop, which does not run
inside itself; it is for scripts and tests. For more information about the
user agent see also
the user agent in the cookbook.
WebSockets¶
WebSocket applications have never been this simple before. Just receive
messages by subscribing to events such as json of
Pyjo.Transaction.WebSocket with
on() and return them with
send().
"""
__DATA__
@@ index.html.ep
<!DOCTYPE html>
<html>
<head>
<title>Echo</title>
<script>
const ws = new WebSocket('<%= url_for('echo').to_abs() %>');
ws.onmessage = function (event) {
document.body.innerHTML += JSON.parse(event.data).msg;
};
ws.onopen = function (event) {
ws.send(JSON.stringify({msg: 'I ♥ Pyjoyment!'}));
};
</script>
</head>
</html>
"""
from Pyjoyment.Lite import *
@websocket('/echo')
def echo(c):
@c.on('json')
def json(c, document):
document['msg'] = f'echo: {document["msg"]}'
c.send({'json': document})
get('/', 'index')
app.start()
For more information about real-time web features see also the real-time web in the cookbook.
JSON-RPC¶
Pyjo.JSON.RPC is a server and a client of JSON-RPC 2.0. A method is a
function, whose parameters the schema of its type hints validates with
schema=True, and to_action() makes the
server the action of a route. A client calls the methods with promises, here
through the user agent of the application, in an async action.
from Pyjo.JSON.RPC import RPC, Client, Error
from Pyjoyment.Lite import *
# A method of JSON-RPC, whose parameters the schema of its type hints validates
rpc = RPC()
@rpc.method(schema=True)
def divide(a: float, b: float) -> float:
if b == 0:
raise Error.new(1, 'Division by zero')
return a / b
# The server, which takes the requests in the body of a POST
post('/rpc', rpc.to_action())
# A client of the server, through the user agent of the application
@get('/divide/<a:num>/<b:num>')
async def quotient(c):
client = Client.new(lambda request: c.ua().post_p('/rpc', json=request).then(lambda tx: tx.res.json()))
try:
c.render(json={'result': await client.call_p('divide', int(c.param('a')), int(c.param('b')))})
except Error as e:
c.render(json={'error': e.message, 'code': e.code}, status=400)
app.start()
You can call the methods from the command line with
Pyjoyment.Command.get, through the server or through the client.
$ ./myapp.py get -M POST -c '{"jsonrpc":"2.0","method":"divide","params":[7,2],"id":1}' /rpc
$ ./myapp.py get /divide/7/2
A calculator with Bootstrap, which is a client of its own server too, is on the page of examples.
Mode¶
You can use the Pyjo.Log object from log to
portably collect debug messages and automatically disable them later in a
production setup by changing the Pyjoyment operating mode, which can
also be retrieved from the attribute mode.
from Pyjoyment.Lite import *
# Prepare mode specific message during startup
msg = 'Development!' if app.mode == 'development' else 'Something else!'
@get('/')
def index(c):
c.app.log.debug('Rendering mode specific message')
c.render(text=msg)
app.log.debug('Starting application')
app.start()
The default operating mode will usually be development and can be changed
with command line options or the PYJO_MODE environment variable. A mode
other than development will raise the log level from trace to
info. All messages will be written to sys.stderr by default.
$ ./myapp.py daemon -m production
Mode changes also affect a few other aspects of the framework, such as the
built-in exception and not_found pages. Once you switch modes from
development to production, no sensitive information will be revealed
on those pages anymore.
Testing¶
Testing your application is as easy as creating a t directory and filling
it with normal Python tests like t/basic.py, which can be a lot of fun
thanks to Pyjo.Test.Pyjo.
from Pyjo.Test import *
import Pyjo.File
import Pyjo.Test.Pyjo
import re
# Portably point to "../myapp.py"
script = Pyjo.File.curfile().dirname().sibling('myapp.py')
t = Pyjo.Test.Pyjo.new(script)
t.get_ok('/').status_is(200).content_like(re.compile(r'Funky'))
done_testing()
Just run your tests with Pyjo.Prove.
$ pyjo-prove -l -v
$ pyjo-prove -l -v t/basic.py
More¶
You can continue with Guides now or take a look at the Mojolicious wiki, which contains a lot more documentation and examples by many different authors.
Ported from Mojolicious::Guides::Tutorial of Mojolicious 9.49.