Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings
This repository was archived by the owner on Aug 24, 2023. It is now read-only.
/gservPublic archive

GServ: Framework for SPAs and REST based services.

License

NotificationsYou must be signed in to change notification settings

javaConductor/gserv

Repository files navigation

gServ is a tool for creating and deploying REST based services using Groovy without the hassle of a container (JBoss, Tomcat, etc.) . Using gServ, you can easily define REST resources as Groovy scripts or embed gServ in your application. gServ is perfect for creating lightweight micro services.
        <br/><h3>Features:</h3>        <ul>            <li>Container Free            <li>Serve static files            <li>Serve Groovy script as REST resources            <li><a href="https://github.com/javaConductor/gserv/wiki/gServ-HATEOAS"> HATEOAS Support</a>            <li>Easy Content Negotiation            <li>Plugin API            <li><a href="https://github.com/javaConductor/gserv/wiki/gServ-Framework">Embeddable</a>            <li><a href="https://github.com/javaConductor/gserv/wiki/gServ-Standalone">Standalone Mode</a>            <li>CORS support            <li>Compression support            <li>ETag support            <li>Basic Authentication            <li> HTTPS        </ul>            <h3>Requirements:</h3>            <ul><li>Java JDK 1.6+</li>                <li>Groovy 2.3+ (Framework only)</li>            </ul><div>    <h3>Basic Concepts</h3>    <table width="90%">        <tr><th>Term</th>             <th>Meaning</th></tr>        <tr><td>Action</td>      <td>HTTP request handler for a particular path/query/method combination.  </td></tr>        <tr><td>Resources</td>      <td>Resources define actions for a particular root path (eg. /books) and its sub-resources (eg. /books/bestSellers). </td></tr>        <tr><td>Server Config</td><td>The config encapsulates any resources, actions, filters, and plugins. </td></tr>        <tr><td>Server Instance</td><td>This is the actual server instance that will listen to the specified port and handle            requests based on its configuration.</td></tr>    </table></div>
gServ can be used in two ways
[Framework](https://github.com/javaConductor/gserv/wiki/gServ-Framework)
[Standalone](https://github.com/javaConductor/gserv/wiki/gServ-Standalone)#Simple Examples
Creating REST Resources

/// create a GServ instancedef gserv = new GServ()

/// Create a Books REST resourcedef bkResource = gserv.resource("/books") {// URI: /books/faqget “/faq”, file(“BooksFaq.html”)

// URI: /books/xyzget “:id”, { id ->    def book = bookService.get( id )    writeJson book}// responds  to /books/allget “/all”, {  ->    def books = bookService.allBooks ()    header “content-type”, “application/json”    writeJSON books}

}

The root path is passed to the GServ.resource() method along with a closure defining the actions for the resource.
Creating a Server Instance

gserv.http {// setup a directory for static filesstatic_root '/public/webapp'

//static FAQ page located at '/public/webapp/App.faq.html'get '/faq', file("App.faq.html")

}.start(8080);

The http() method creates a GServInstance that can later listen on a port and handle HTTP requests. This server instancedefines static roots usually used for templates for single-page apps and a single FAQ page.Then, after the server instance is returned from the http() method, we can immediately call start(8080) on it.
Adding Resources to a Server Instance

def bkResource = gserv.resource("/books") { ... }def userResource = gserv.resource("/users") { ... }

gserv.http {// setup a directory for static filesstatic_root "/public/webapp"

// static FAQ page located at '/public/webapp/App.faq.html'get '/faq', file('App.faq.html')/// add Book and User REST resources to our GServ instanceresource bkResourceresource userResource

}.start(8080);

A server instance can be created by simply adding resources. Here we add our 2 resources: bkResources anduserResources. Now, all URIs related to both resources are available once the instance is started. This instance alsodefines a static_root which tells gserv where to find static files such as the FAQ page which should be at /public/webapp/App.faq.html.

About

GServ: Framework for SPAs and REST based services.

Resources

License

Stars

Watchers

Forks

Packages

No packages published

[8]ページ先頭

©2009-2025 Movatter.jp