Masonite 1.4 brings a lot of awesome features to the Masonite framework such as real time support with Pusher and Ably drivers, template caching, easy email sending with SMTP and Mailgun drivers, simple upload support with disk and Amazon S3 drivers. Only a few of the powerful features of Masonite are in this post so be sure to dive further by:

Starring the repo: https://github.com/MasoniteFramework/masonite Or reading the docs: https://masoniteframework.gitbooks.io/docs/content/

For those that watch to a watch a simple video that explains this post in more detail then feel free to watch the video below.

Real-time Support

Modern web frameworks need ways to keep up with the needs of modern web applications so Masonite 1.4 comes with a broadcast feature. Out of the box Masonite ships with Pusher and Ably drivers which are just third party services for implementing web sockets. Those of you who have used Pusher already know how great these services can be.

Masonite ships with a config/broadcast.py configuration file with a few preset driver settings which are very straight forward. Just put your authentication settings in your .env file. Using it in our controller method will look something like:

def show(self, Broadcast):

Broadcast.channel('channel-name', 'message')

That’s it. You have just broadcasted your event to Pusher (or whatever your default driver is).

Upload Support

There are two main methods in which we want to typically upload images.

Upload an image to our disk (our file system)

Upload an image to Amazon S3

Since these are the two most common scenario’s, Masonite comes with both. Uploading to a disk is simple. If we have a form like this:

<form action="/upload" method="POST" enctype="multipart/form-data"> {{ csrf_field|safe }} <input type="file" name="file_upload"> <input type="submit" value="Upload"> </form>

Then we can simply grab that file_upload input which will return our image and upload it. This will look like:

def show(self, Upload):

Upload.store(request().input(file_upload))

Done. It will be stored in the default directory which is storage/uploads by default.

We can also use an UploadManager which we can use to specify the driver we want to use. By putting your Amazon S3 credentials in the .env file we can do this:

def show(self, UploadManager):

UploadManager.driver('s3').store(request().input(file_upload))

Bam! We can now upload directly to Amazon S3. Watch the video to see the results.

Templates Caching

There are likely to be high traffic areas of your website that:

receive a lot of hits

have a high order of magnitude (multiple for loops inside for loops)

don’t change on a per week, per day, per minute or per second basis

These types of templates could be landing pages, home pages, about or contact pages, etc etc.

These templates are perfect for caching. Instead of having Masonite render the templates over and over again, we can just cache it. Instead of Masonite rendering the template over and over it will just read it from the cache.

We can now do something like:

def show(self):

return view('complexity').cache_for(8, 'seconds')

The template will now be cached for 8 seconds. When the cache expires, Masonite will render as usual and cache another copy for 8 seconds. All users who hit that page will see the cached version instead of the rendered version until the cache expires.

Mail Support

Nearly every side project you have uses or could benefit from sending emails. Whether it’s user account information like notifcations or success messages or even sending an email to the site admin that a new user signed up. Either way, sending email is simple:

def show(self, Mail):

Mail.to('user@email.com').send('Welcome!')

This will of course send a simple text of “Welcome!” to the user at that email address. We can also send entire templates:

def show(self, Mail):

Mail.to('user@email.com').template('welcome').send()