- Notifications
You must be signed in to change notification settings - Fork30
A full stack web framework written in janet
License
joy-framework/joy
Folders and files
Name | Name | Last commit message | Last commit date | |
---|---|---|---|---|
Repository files navigation
Joy is a full stack web framework written injanet
(use joy)(route:get"/":home)(defnhome [request] (text/plain"You found joy!"))(defapp (app))(server app9001)
First make surejanet is installed
Next, install the joy cli like this
jpm install joy
Hopefully thejoy
executable will be on your path and ready to roll. If it isn't and you're like me and use homebrew, add this to your.zprofile
:
export PATH=/usr/local/Cellar/janet/<your janet version here>/bin:$PATH
Then make sure you reload the profile:
source~/.zprofile
Now, run the following from your terminal
joy new my-joy-project
This should create a new directory calledmy-joy-project
and it should create a few files and thingsto get you started.
Now that we have a project set up, it's time to test it out in the browser:
joy server
This should start an http server that's listening athttp://localhost:9001.
Next, let's create a database, a table and connect it with routes and a few functions for handling requests.
If you aren't already in themy-joy-project
directory, go ahead and get in there. Now run
joy create db
This creates a new empty database nameddev.sqlite3
.
The default template doesn't assume you want a database so you'll need to connect to it inmain.janet
:
; # main.janet(defnmain [& args] (db/connect (env:database-url)) (server app (env:port)) (db/disconnect))
Run this to create a new migration with a table with a few columns:
joy create table account'email text unique not null''password text not null'
This has created one file in your db/migrations folder that is waiting to get applied to the database.
Run this from your terminal
joy migrate
This will migrate your database and create a new filedb/schema.sql
In joy there are no ORMs, no classes, and no objects, just functions that take requests and return responses.
Let's generate a few routes for the table from earlier:
joy create controller account
Those commands have created another new file:routes/account.janet
and updated yourmain.janet
file with an import statement so the account routes get set up.
Go ahead and check out the newaccount
routes in the browser now:http://localhost:9001/accounts
Joy can do a lot more than that,check out the docs here
I wanted something that felt likecoast but took so little resources (memory + cpu) I could run dozens (if not hundreds) of websites on a cheapVPS.
In order to make using joy more portable, we wanted to include a Dockerfile that creates an easy place for you to mount your code in and run joy without having to install anything or manage permissions on your local.
About
A full stack web framework written in janet