This repository was archived by the owner on Aug 24, 2023. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 9
gServ Custom Action Request Matching
Lee Collins edited this page Apr 21, 2015
·
1 revision
#Custom Matching Custom matching allows user-defined criteria. Criteria may specify header values, including content type and accept. Actions may be defined with custom matchers. There are 3 builtin matchers:
onlyIfContentType( types... ) onlyIfAccepts( types... ) onlyIfHeader( header, values... )
GServ.Resource('/books') { get "/:id:Integer" , onlyIfAccepts("text/json") { bookId -> def bk = service.getBook(bookId) writeJson [book: bk] } }.start(8080);
####Notes If the request does not have an Accept header with 'text/json' a 404 status code may be returned to the client.
GServ.Resource('/books') { put "/:id:Integer" , onlyIfContentType("text/json") { Book book, id -> def bk = service.updateBook(id, book) writeJson [book: bk] } }.start(8080);
####Notes If the request does not have an Content-Type header with 'text/json' a 404 status code may be returned to the client.
GServ.Resource('/books') { get "/:id:Integer" , onlyIfHeader('Accept-Encoding'."gzip") { bookId -> def bk = service.getBook() writeJson [book: bk] } }.start(8080);
####Notes If the request does not have an Accept-Encoding header including 'gzip', a 404 status code may be returned to the client.
gServ © 2014-2017 Lee Collins. All rights reserved.