Skip to content
Web framework for Racket.
Branch: master
Clone or download

Latest commit

Fetching latest commit…
Cannot retrieve the latest commit at this time.


Type Name Latest commit message Commit time
Failed to load latest commit information.
examples bug fix and will use middleware rewirte cros Feb 26, 2020
vela-doc middleware Feb 22, 2020
vela-lib Fix bug Apr 9, 2020
vela handle file Feb 23, 2020
.gitignore .gitignore May 10, 2019
CNAME Create CNAME Feb 24, 2020 update readme Mar 5, 2020
_config.yml Set theme jekyll-theme-hacker Feb 24, 2020


Simple web framework to build restful app in Racket.


  • Web handlers with Function or Class.
  • Friendly way to define url routers.
  • Pluggable middlewares when request and response.
  • Request params check and collector.
  • Entirely on the racket webserver lib.


raco pkg install vela


  #lang racket
  (require vela)

  (define index
    (lambda (req)
      (jsonify (hash 'msg "hello world!" ))))

  (define routers
      (url "/" index "index")))

  (app-run routers #:port 8000)

Define Handler

There two ways to define a handler.

Use handler%

(define hello-handler
  (class handler%

    (define/public (get [id null])
      (displayln id)
      (jsonify (hash 'code 200 'msg "handle get" )))

    (define/public (post)
      (jsonify (hash 'code 200 'msg "handle post" )))

    (define/public (put id)
      (jsonify (hash 'code 200 'msg "handle put" )))

    (define/public (delete id)
      (jsonify (hash 'code 200 'msg "handle delete" )))


Use simple function:

(define index-handler
  (lambda (req)
    (jsonify (hash 'code 200 'msg "hello api" ))))


(define (index-handler req)
  (jsonify (hash 'code 200 'msg "hello api" )))


Use jsonify to return JSON content.

(jsonify (hash 'name "rosso" 'msg "hello world!"))

Use render to render TEXT or HTML template.

plain text

(render "hello world!")

HTML template

(require web-server/templates)
(render (include-template "index.html"))

URL routes

Use urls and url function to define route.

(define routers
    (url "/" index-handler "handler with function")))

Use url-group grouping routes.

(define api-v1 (url-group "/api/v1"))

(define routers
      (url "/hellos" hello-handler "hello-list/post")
      (url "/hello/:id" hello-handler "hello-put/delete/get"))))

Use middleware

Use middleware in url or url-group.


(define (index-handler req)
  (jsonify "hello!"))

(define (login-required req)
  (jsonify "user not login"))

(define (print-current-time req)
  (displayln (current-seconds)))

(define (say-hi req resp)
  (jsonify "hi"))

(define api-v1 
  (url-group "/cc" #:on-request (list login-required) #:on-response (list say-hi)))

(define routers
    (url "/" index-handler  #:on-request (list print-current-time) "index")

      (url "/index" index-handler)
      (url "/index1" index-handler #:on-request (list login-required) #:on-response (list say-hi) "index1"))))

request middleware must set a request argument. response middleware must set request and response argument.

Customize Headers

You need require make-header from request-structs package.

   (only-in web-server/http/request-structs

(define my-headers
    (make-header #"Access-Control-Allow-Origin" #"*")
    (make-header #"Access-Control-Allow-Methods" #"PUT, POST, GET, DELETE, PATCH, OPTIONS")))

Customize Response

Use responsefuction

(define (my-custom-rsp xml-doc)
    #:headers my-headers
    #:mime #"application/xml"
    #:body xml-doc))


Very simple apps build with Vela in the examples folder.


Licensed under the MIT License.

You can’t perform that action at this time.