Skip to content
Permalink
master
Switch branches/tags

Name already in use

A tag already exists with the provided branch name. Many Git commands accept both tag and branch names, so creating this branch may cause unexpected behavior. Are you sure you want to create this branch?
Go to file
 
 
Cannot retrieve contributors at this time
# TOTAL DRAFT
# this is a lanugage for describing an API. My thought is that it will be parsed by PHP (so I can call PHP functions from it) at first, and perhaps slowly moved to a much faster language if the concept proves solid.
# this document in particular is an example of how I would write a very simple web app in PHP. I'm aiming this to be a middleware for single-page apps (e.g. something written in Angular or React) where the developer wants to quickly build an API which is little more than a delivery system for static files and SQL calls.
# comments in Lanky are preceded with a hash
# we can route to a static file using the "static" keyword
# here, a call of any type (get, post, etc) to / is given index.html
REQUEST /
static /static/index.html
# here is a post to login
# it takes two required (!) parameters in the post body
# it then calls the php function login (defined where?)
POST /login/!user/!password
php login($user, $password)
# register takes two required (!) and one optional parameter
# then it calls the register function
POST /register/!user/!password/:email
php register($user, $password, $email)
# if the user is authenticated and they attempt to get the profile page without params we show them their own user profile
# notice that we are just returning the results of an SQL query against some database. The frontend of the app handles the displaying of that data
# this is the main scenario where this language is useful
AUTH GET /profile
sql SELECT * FROM profiles WHERE user_id={{$_SESSION['user_id']}}
# throw a 403 if the user is not logged in
# the frontend should handle this case and present the login screen
# (perhaps for simplicity we would just do a php header('HTTP/1.0 403 Forbidden') call)?
GET /profile
code 403
# here is a get request with a required get param. I'm thinking this handles both /profile/1 and /profile?user_id=1 (or maybe that's a setting somewhere)?
# I have a feeling we'll have to change the syntax for the SQL/PHP line for security purposes.
AUTH GET /profile/!user_id
sql SELECT * FROM profiles WHERE user_id={{$user_id}}
# If the user isn't authed then they only get some of the data.
GET /profile/!user_id
sql SELECT username FROM profiles WHERE user_id={{$user_id}}