{"size": 1316, "ext": "scrbl", "max_stars_repo_path": "vela-doc/vela/handler.scrbl", "max_stars_repo_name": "worktopia-io/vela", "max_stars_repo_stars_event_min_datetime": "2019-04-29T12:41:38.000Z", "max_stars_repo_stars_event_max_datetime": "2022-01-22T06:25:33.000Z", "max_issues_repo_path": "vela-doc/vela/handler.scrbl", "max_issues_repo_name": "worktopia-io/vela", "max_issues_repo_issues_event_min_datetime": "2020-02-14T10:23:15.000Z", "max_issues_repo_issues_event_max_datetime": "2020-04-09T11:04:43.000Z", "max_forks_repo_path": "vela-doc/vela/handler.scrbl", "max_forks_repo_name": "nuty/vela", "max_forks_repo_forks_event_min_datetime": "2020-04-09T06:47:23.000Z", "max_forks_repo_forks_event_max_datetime": "2022-01-25T10:33:06.000Z"}
{"max_stars_count": 48, "max_issues_count": 2, "max_forks_count": 3, "avg_line_length": 18.8, "max_line_length": 71, "alphanum_fraction": 0.6306990881}
#lang scribble/manual
@title[#:style '(toc)]{Web handler}

Vela support Function based handler or Class based handler.


@larger{
  Function based handler
}

Function based handler use to write condational html app. 

@(racketblock

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

  @bold{
    @italic{or}
  }

@(racketblock
  (define (index req)
    (jsonify (hash 'code 200 'msg "hello world!" ))))


@larger{
  Class based handler
}

Class based handler use to build RESTful API. 

@(racketblock

(define hello-world%
  (class handler%

    (define/public (get [id null])
      (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" )))
   
    (define/public (patch)
      (jsonify (hash 'code 200 'msg "handle patch" )))

    (super-new))))

Get request context in class use (get-field request this) inside class.

@codeblock|{
  (define hello-world%
    (class handler%

      (define/public (get [id null])
        (define req (get-field request this))
        (jsonify (hash 'code 200 'msg "handle get" )))

    (super-new)))
}|


