~lastrosade/getcraft

Settings moved to settings.json, routes moved to settings.json, mime_type now specifiable for files.
Update README.md

refs

master
browse  log 

clone

read-only
https://git.sr.ht/~lastrosade/getcraft
read/write
git@git.sr.ht:~lastrosade/getcraft

You can also use your local clone with git send-email.

#getcraft

a simple json "API" engine

#Routes

Routes are in the routes.json file

#Arguments

  • req = link (/link/to/thing)
  • type = What you want to do with your link
  • res = what is the target

#Types

  • text, sends res as text

  • file, sends file content

  • directory, sends files contents in directory as json

    for example:

    [
        {
            "filename": "file1",
            "content": "CoolFile"
        },
        {
            "filename": "file2",
            "content": "Nice content"
        }
    ]
    
  • route

    • get, returns the content of the routing array as json
    • refresh, refresh the routes array
#optional
  • mime = sets the "Content-Type" header
  • status = force http status code

#Example

{
    "routes": [

        // Respond with text
        {
            "req": "/text",
            "type": "text",
            "res": "text"
        },
        // Respond with the content of a file
        {
            "req": "/index",
            "type": "file",
            "res": "src/index.lua"
        },
        // Respond with a json containing file names and content
        {
            "req": "/src",
            "type": "directory",
            "res": "src/"
        },

        // Get the possible routes and their actions
        {
            "req": "/rg",
            "type": "route get"
        },
        // Refresh the routes file
        {
            "req": "/rr",
            "type": "route refresh"
        },

        // Optionally specify the mime type of the file
        {
            "req": "/index_mime",
            "type": "file",
            "mime": "text/lua",
            "res": "src/index.lua"
        },
        // Optionally give http status code
        {
            "req": "/500",
            "type": "text",
            "status": 500,
            "res": "oh no"
        }
    ]
}