{"id":39020,"date":"2016-07-07T15:00:53","date_gmt":"2016-07-07T12:00:53","guid":{"rendered":"http:\/\/examples.javacodegeeks.com\/?p=39020"},"modified":"2023-11-09T15:23:43","modified_gmt":"2023-11-09T13:23:43","slug":"grails-rest-example","status":"publish","type":"post","link":"https:\/\/examples.javacodegeeks.com\/jvm-languages\/groovy\/grails\/grails-rest-example\/","title":{"rendered":"Grails REST Example"},"content":{"rendered":"<p>In this example we shall show you how to create RESTful APIs using\u00a0Grails. Exposing your application functionality to other applications is always achieved using web services. Grails provides several features that make implementing a RESTful web service in Grails easy using\u00a0a RESTful resource.<\/p>\n<p>Originally, web services grew in popularity as a means for system integration. But with the recent popularity of sites such as Google Maps and Amazon.com, and social networking sites like Facebook, there is an expectation that public APIs should be offered so users can create new and innovative client applications. When these clients combine multiple services from multiple providers, they are referred to as <a href=\"http:\/\/en.wikipedia.org\/wiki\/Mashup_(web_application_hybrid)\">mashups<\/a>. They can include command-line applications, desktop applications, web applications, or some type of widget.<\/p>\n<p>In this example, we will learn how to expose your application functionality as a Representational State Transfer (REST) web service for Finacial market order gateway application to provide access to domain objects. This RESTful web service will be able to return either XML or JavaScript Object Notation (JSON), depending on the needs of the client application. This web service will also be designed to take advantage of convention over configuration for exposing CRUD functionality for any Grails domain model.<br \/>\n<span data-sheets-value=\"{&quot;1&quot;:2,&quot;2&quot;:&quot;&quot;}\" data-sheets-userformat=\"{&quot;2&quot;:515,&quot;3&quot;:{&quot;1&quot;:0},&quot;4&quot;:{&quot;1&quot;:2,&quot;2&quot;:16777215},&quot;12&quot;:0}\">[ulp id=&#8217;kHqyxwGNoyzYAfPN&#8217;]<\/span><\/p>\n<h2>1. Project Environment<\/h2>\n<ol>\n<li>Groovy\/Grails Tool Suite<\/li>\n<li>Grails\u00a03.0.10<\/li>\n<li>Groovy 2.4.5<\/li>\n<li>JDK 1.8<\/li>\n<\/ol>\n<h2>2. Grails Project<\/h2>\n<h3>2.1. Create new project<\/h3>\n<p>We will start creating a new Grails 3 project using the following Grails command line.<\/p>\n<pre class=\"brush:bash\">grails create-app grails-rest-example --profile=web-api\n<\/pre>\n<h3>2.2. Project Structure<\/h3>\n<ul>\n<li><code>build<\/code> directory where build related files like compiled classes and assembled packages are located.<\/li>\n<li><code>gradle<\/code> directory contains the Gradle Wrapper that allows you to build the project without a local Gradle installation.<\/li>\n<li><code>conf<\/code> directory contains the YAML configuration files and Logback configuration.<\/li>\n<li><code>init<\/code> directory contains Bootstrap.groovy and the new Application main class which looks like main class in Spring Boot.<\/li>\n<li><code>controllers<\/code> directory contains controllers classes.<\/li>\n<li><code>domain<\/code> directory contains location of domain classes.<\/li>\n<li><code>i18n<\/code> directory contains location of message bundles for i18n.<\/li>\n<li><code>services<\/code> directory contains location of services.<\/li>\n<li><code>util<\/code> directory contains special utility classes.<\/li>\n<li><code>src<\/code> folder is an optional directory for Groovy source files of types other than those in grails-app\/*<\/li>\n<li><code>build.gradle<\/code> and <code>gradle.properties<\/code> contain the build configuration.<\/li>\n<\/ul>\n<h2>3. REST Web Service<\/h2>\n<p>REST is not really a technology itself, but more like an architectural pattern. REST is very simple and just involves using plain XML or JSON as a communication medium, combined with URL patterns that are &#8220;representational&#8221; of the underlying system, and HTTP methods such as <code>GET<\/code>, <code>PUT<\/code>, <code>POST<\/code> and <code>DELETE<\/code>.<br \/>\nEach HTTP method maps to an action type. For example <code>GET<\/code> for retrieving order, <code>POST<\/code> for submitting new order, <code>PUT<\/code> for updating submitted one and so on.<div style=\"display:inline-block; margin: 15px 0;\"> <div id=\"adngin-JavaCodeGeeks_incontent_video-0\" style=\"display:inline-block;\"><\/div> <\/div><\/p>\n<p>Grails includes flexible features that make it easy to create RESTful APIs. Creating a RESTful resource can be as simple as one line of code, as demonstrated in the next section.<\/p>\n<h3>3.1. Domain classes as REST resources<\/h3>\n<p>The easiest way to create a RESTful API in Grails is to expose a domain class as a REST resource. Simply by adding the Resource transformation and specifying a URI, your domain class will automatically be available as a REST resource in either XML or JSON formats. The transformation will automatically register the necessary RESTful URL mapping and create a controller called <code>OrderController<\/code>.<br \/>\nAlso, If you wish to change the default to return JSON instead of XML, you can do this by setting the formats attribute of the Resource transformation:<\/p>\n<pre class=\"brush:java\">@Resource(uri='\/api\/orders', formats=['json', 'xml'])\nclass Order {\n...\n}\n<\/pre>\n<p><span style=\"text-decoration: underline;\"><em>Order.groovy:<\/em><\/span><\/p>\n<pre class=\"brush:java\">package grails.rest.example\n\nimport grails.rest.*\n@Resource(uri='\/api\/orders', formats=['json', 'xml'])\nclass Order {\n\t\n\tLong id\n\tString stock\n\tString side\n\tDouble price\n\tLong size\n\t\n\tstatic mapping = {\n\t\tversion false\n\t\ttable 'orders'\n\t\tid column: 'id', generator:'native', params:[sequence:'order_seq']\n\t  }\n\t\n    static constraints = {\n\t\t\tstock blank:false\n\t\t\tside blank:false\n\t\t\tprice blank:false\n\t\t\tsize blank:false\n\t}\n}\n<\/pre>\n<h2>4. Running Grails Web Service<\/h2>\n<h3>4.1. Initial Order Data<\/h3>\n<p>We added some orders data to <code>BootStrap.groovy<\/code>, then we run our Grails application as a spring boot app using <code>Application.groovy<\/code>.<\/p>\n<p><em><span style=\"text-decoration: underline;\">BootStrap.groovy:<\/span><\/em><\/p>\n<pre class=\"brush:java\">import grails.rest.example.Order\n\nclass BootStrap {\n\n    def init = { servletContext -&gt;\n        new Order(stock:\"AAPL\", side:\"S\", price:200, size:1000).save()\n        new Order(stock:\"IBM\", side:\"B\", price:300, size:2000).save()\n\t\tnew Order(stock:\"JNJ\", side:\"T\", price:150, size:3000).save()\n    }\n    def destroy = {\n    }\n}\n<\/pre>\n<p><span style=\"text-decoration: underline;\"><em>Application.groovy:<\/em><\/span><\/p>\n<pre class=\"brush:java\">import grails.rest.example.Order\n\nclass BootStrap {\n\n    def init = { servletContext -&gt;\n        new Order(stock:\"AAPL\", side:\"S\", price:200, size:1000).save()\n        new Order(stock:\"IBM\", side:\"B\", price:300, size:2000).save()\n\t\tnew Order(stock:\"JNJ\", side:\"T\", price:150, size:3000).save()\n    }\n    def destroy = {\n    }\n}\n<\/pre>\n<h3>4.2. List Orders<\/h3>\n<p>Hitting the URL <code>http:\/\/localhost:8080\/api\/orders<\/code>, which will render the response with the default JSON format like:<\/p>\n<pre class=\"brush:bash\">[{\n\t\"class\": \"grails.rest.example.Order\",\n\t\"id\": 1,\n\t\"price\": 200.0,\n\t\"side\": \"S\",\n\t\"size\": 1000,\n\t\"stock\": \"AAPL\"\n}, {\n\t\"class\": \"grails.rest.example.Order\",\n\t\"id\": 2,\n\t\"price\": 300.0,\n\t\"side\": \"B\",\n\t\"size\": 2000,\n\t\"stock\": \"IBM\"\n}, {\n\t\"class\": \"grails.rest.example.Order\",\n\t\"id\": 3,\n\t\"price\": 150.0,\n\t\"side\": \"T\",\n\t\"size\": 3000,\n\t\"stock\": \"JNJ\"\n}]\n<\/pre>\n<p>Also, we can set the desired response format using the file extension in the URI, hitting the URL <code>http:\/\/localhost:8080\/api\/orders.xml<\/code>, will render the response with the XML format like:[ulp id='kHqyxwGNoyzYAfPN']<\/p>\n<pre class=\"brush:xml\">&lt;?xml version=\"1.0\" encoding=\"UTF-8\"?&gt;\n&lt;list&gt;\n   &lt;order id=\"1\"&gt;\n      &lt;price&gt;200.0&lt;\/price&gt;\n      &lt;side&gt;S&lt;\/side&gt;\n      &lt;size&gt;1000&lt;\/size&gt;\n      &lt;stock&gt;AAPL&lt;\/stock&gt;\n   &lt;\/order&gt;\n   &lt;order id=\"2\"&gt;\n      &lt;price&gt;300.0&lt;\/price&gt;\n      &lt;side&gt;B&lt;\/side&gt;\n      &lt;size&gt;2000&lt;\/size&gt;\n      &lt;stock&gt;IBM&lt;\/stock&gt;\n   &lt;\/order&gt;\n   &lt;order id=\"3\"&gt;\n      &lt;price&gt;150.0&lt;\/price&gt;\n      &lt;side&gt;T&lt;\/side&gt;\n      &lt;size&gt;3000&lt;\/size&gt;\n      &lt;stock&gt;JNJ&lt;\/stock&gt;\n   &lt;\/order&gt;\n&lt;\/list&gt;\n<\/pre>\n<p>Also, instead of using the file extension in the URI, you can also obtain a JSON response by issuing a <code>GET<\/code> request while using the <code>ACCEPT<\/code> header. Here&#8217;s an example using the Unix curl tool:<\/p>\n<pre class=\"brush:bash\">curl -i -H \"Accept: application\/json\" localhost:8080\/api\/orders\n<\/pre>\n<p><span style=\"text-decoration: underline;\"><em>Output:<\/em><\/span><\/p>\n<pre class=\"brush:bash; wrap-lines:false\">HTTP\/1.1 200 OK\nServer: Apache-Coyote\/1.1\nX-Application-Context: application:development\nContent-Type: application\/json;charset=UTF-8\nTransfer-Encoding: chunked\nDate: Wed, 06 Jul 2016 21:52:22 GMT\n\n[{\"class\":\"grails.rest.example.Order\",\"id\":2,\"price\":300.0,\"side\":\"B\",\"size\":2000,\"stock\":\"IBM\"},{\"class\":\"grails.rest.example.Order\",\"id\":3,\"price\":150.0,\"side\":\"T\",\"size\":3000,\"stock\":\"JNJ\"},{\"class\":\"grails.rest.example.Order\",\"id\":4,\"price\":200.0,\"side\":\"S\",\"size\":5000,\"stock\":\"TWT\"}]\n<\/pre>\n<h3>4.3. Submit Order<\/h3>\n<p>We can create a new order by issuing a <code>POST<\/code> request:<\/p>\n<pre class=\"brush:bash\">curl -i -X POST -H \"Content-Type: application\/json\" -d '{\"price\": 200,\"side\": \"S\",\"size\": 5000,\"stock\": \"TWT\"}' localhost:8080\/api\/orders\n<\/pre>\n<p><span style=\"text-decoration: underline;\"><em>Output:<\/em><\/span><\/p>\n<pre class=\"brush:bash; wrap-lines:false\">HTTP\/1.1 201 Created\nServer: Apache-Coyote\/1.1\nX-Application-Context: application:development\nLocation: http:\/\/localhost:8080\/api\/orders\/4\nContent-Type: application\/json;charset=UTF-8\nTransfer-Encoding: chunked\nDate: Wed, 06 Jul 2016 21:35:14 GMT\n\n{\"class\":\"grails.rest.example.Order\",\"id\":4,\"price\":200.0,\"side\":\"S\",\"size\":5000,\"stock\":\"TWT\"}\n<\/pre>\n<h3>4.4. Update Order<\/h3>\n<p>We can create a new order by issuing a <code>PUT<\/code> request:<\/p>\n<pre class=\"brush:bash\">curl -i -X PUT -H \"Content-Type: application\/json\" -d '{\"price\": 210,\"size\": 500}' localhost:8080\/api\/orders\/1\n<\/pre>\n<p><span style=\"text-decoration: underline;\"><em>Output:<\/em><\/span><\/p>\n<pre class=\"brush:bash; wrap-lines:false\">HTTP\/1.1 200 OK\nServer: Apache-Coyote\/1.1\nX-Application-Context: application:development\nLocation: http:\/\/localhost:8080\/api\/orders\/1\nContent-Type: application\/json;charset=UTF-8\nTransfer-Encoding: chunked\nDate: Wed, 06 Jul 2016 21:37:41 GMT\n\n{\"class\":\"grails.rest.example.Order\",\"id\":1,\"price\":210.0,\"side\":\"S\",\"size\":500,\"stock\":\"AAPL\"}\n<\/pre>\n<h3>4.5. Delete Order<\/h3>\n<p>We can create a new order by issuing a <code>DELETE<\/code> request:<\/p>\n<pre class=\"brush:bash\">curl -i -X DELETE localhost:8080\/api\/orders\/1\n<\/pre>\n<p><span style=\"text-decoration: underline;\"><em>Output:<\/em><\/span><\/p>\n<pre class=\"brush:bash; wrap-lines:false\">HTTP\/1.1 204 No Content\nServer: Apache-Coyote\/1.1\nX-Application-Context: application:development\nContent-Type: application\/json;charset=UTF-8\nDate: Wed, 06 Jul 2016 21:39:12 GMT\n<\/pre>\n<p>As you can see, the Resource transformation enables all of the HTTP method verbs on the resource. You can enable <code>read-only<\/code> capabilities by setting the <code>readOnly<\/code> attribute to true. However, In this case <code>POST<\/code>, <code>PUT<\/code> and <code>DELETE<\/code> requests will be forbidden.<\/p>\n<pre class=\"brush:java\">@Resource(uri='\/api\/orders', formats=['json', 'xml'], readOnly=true)\nclass Order {\n...\n}\n<\/pre>\n<h2>5. Download the Source Code<\/h2>\n<p>This was an example on\u00a0how to create a Grails REST web service.<\/p>\n<div class=\"download\"><strong>Download<\/strong><br \/>\nYou can download the full source code of this example here: <a title=\"Grails REST Web Service Example Code\" href=\"http:\/\/examples.javacodegeeks.com\/wp-content\/uploads\/2016\/07\/grails-rest-example.zip\" target=\"_blank\" rel=\"noopener\"><strong>GrailsRESTWebServiceExampleCode.zip<\/strong><\/a><\/div>\n","protected":false},"excerpt":{"rendered":"<p>In this example we shall show you how to create RESTful APIs using\u00a0Grails. Exposing your application functionality to other applications is always achieved using web services. Grails provides several features that make implementing a RESTful web service in Grails easy using\u00a0a RESTful resource. Originally, web services grew in popularity as a means for system integration. &hellip;<\/p>\n","protected":false},"author":24,"featured_media":27333,"comment_status":"open","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[1528],"tags":[1214,474],"class_list":["post-39020","post","type-post","status-publish","format-standard","has-post-thumbnail","hentry","category-grails","tag-grails","tag-rest-2"],"yoast_head":"<!-- This site is optimized with the Yoast SEO plugin v26.5 - https:\/\/yoast.com\/wordpress\/plugins\/seo\/ -->\n<title>Grails REST Example - Java Code Geeks<\/title>\n<meta name=\"description\" content=\"In this example we shall show you how to create RESTful APIs using\u00a0Grails. Exposing your application functionality to other applications is always\" \/>\n<meta name=\"robots\" content=\"index, follow, max-snippet:-1, max-image-preview:large, max-video-preview:-1\" \/>\n<link rel=\"canonical\" href=\"https:\/\/examples.javacodegeeks.com\/jvm-languages\/groovy\/grails\/grails-rest-example\/\" \/>\n<meta property=\"og:locale\" content=\"en_US\" \/>\n<meta property=\"og:type\" content=\"article\" \/>\n<meta property=\"og:title\" content=\"Grails REST Example - Java Code Geeks\" \/>\n<meta property=\"og:description\" content=\"In this example we shall show you how to create RESTful APIs using\u00a0Grails. Exposing your application functionality to other applications is always\" \/>\n<meta property=\"og:url\" content=\"https:\/\/examples.javacodegeeks.com\/jvm-languages\/groovy\/grails\/grails-rest-example\/\" \/>\n<meta property=\"og:site_name\" content=\"Examples Java Code Geeks\" \/>\n<meta property=\"article:publisher\" content=\"https:\/\/www.facebook.com\/javacodegeeks\" \/>\n<meta property=\"article:author\" content=\"https:\/\/www.facebook.com\/ashraf.sar7an\" \/>\n<meta property=\"article:published_time\" content=\"2016-07-07T12:00:53+00:00\" \/>\n<meta property=\"article:modified_time\" content=\"2023-11-09T13:23:43+00:00\" \/>\n<meta property=\"og:image\" content=\"https:\/\/examples.javacodegeeks.com\/wp-content\/uploads\/2015\/09\/grails-logo.jpg\" \/>\n\t<meta property=\"og:image:width\" content=\"150\" \/>\n\t<meta property=\"og:image:height\" content=\"150\" \/>\n\t<meta property=\"og:image:type\" content=\"image\/jpeg\" \/>\n<meta name=\"author\" content=\"Ashraf Sarhan\" \/>\n<meta name=\"twitter:card\" content=\"summary_large_image\" \/>\n<meta name=\"twitter:creator\" content=\"@http:\/\/twitter.com\/ashraf_sarhan\" \/>\n<meta name=\"twitter:site\" content=\"@javacodegeeks\" \/>\n<meta name=\"twitter:label1\" content=\"Written by\" \/>\n\t<meta name=\"twitter:data1\" content=\"Ashraf Sarhan\" \/>\n\t<meta name=\"twitter:label2\" content=\"Est. reading time\" \/>\n\t<meta name=\"twitter:data2\" content=\"4 minutes\" \/>\n<script type=\"application\/ld+json\" class=\"yoast-schema-graph\">{\"@context\":\"https:\/\/schema.org\",\"@graph\":[{\"@type\":\"Article\",\"@id\":\"https:\/\/examples.javacodegeeks.com\/jvm-languages\/groovy\/grails\/grails-rest-example\/#article\",\"isPartOf\":{\"@id\":\"https:\/\/examples.javacodegeeks.com\/jvm-languages\/groovy\/grails\/grails-rest-example\/\"},\"author\":{\"name\":\"Ashraf Sarhan\",\"@id\":\"https:\/\/examples.javacodegeeks.com\/#\/schema\/person\/553eb8f56e9ffb76e6bcc85d6157fc91\"},\"headline\":\"Grails REST Example\",\"datePublished\":\"2016-07-07T12:00:53+00:00\",\"dateModified\":\"2023-11-09T13:23:43+00:00\",\"mainEntityOfPage\":{\"@id\":\"https:\/\/examples.javacodegeeks.com\/jvm-languages\/groovy\/grails\/grails-rest-example\/\"},\"wordCount\":760,\"commentCount\":1,\"publisher\":{\"@id\":\"https:\/\/examples.javacodegeeks.com\/#organization\"},\"image\":{\"@id\":\"https:\/\/examples.javacodegeeks.com\/jvm-languages\/groovy\/grails\/grails-rest-example\/#primaryimage\"},\"thumbnailUrl\":\"https:\/\/examples.javacodegeeks.com\/wp-content\/uploads\/2015\/09\/grails-logo.jpg\",\"keywords\":[\"Grails\",\"REST\"],\"articleSection\":[\"Grails\"],\"inLanguage\":\"en-US\",\"potentialAction\":[{\"@type\":\"CommentAction\",\"name\":\"Comment\",\"target\":[\"https:\/\/examples.javacodegeeks.com\/jvm-languages\/groovy\/grails\/grails-rest-example\/#respond\"]}]},{\"@type\":\"WebPage\",\"@id\":\"https:\/\/examples.javacodegeeks.com\/jvm-languages\/groovy\/grails\/grails-rest-example\/\",\"url\":\"https:\/\/examples.javacodegeeks.com\/jvm-languages\/groovy\/grails\/grails-rest-example\/\",\"name\":\"Grails REST Example - Java Code Geeks\",\"isPartOf\":{\"@id\":\"https:\/\/examples.javacodegeeks.com\/#website\"},\"primaryImageOfPage\":{\"@id\":\"https:\/\/examples.javacodegeeks.com\/jvm-languages\/groovy\/grails\/grails-rest-example\/#primaryimage\"},\"image\":{\"@id\":\"https:\/\/examples.javacodegeeks.com\/jvm-languages\/groovy\/grails\/grails-rest-example\/#primaryimage\"},\"thumbnailUrl\":\"https:\/\/examples.javacodegeeks.com\/wp-content\/uploads\/2015\/09\/grails-logo.jpg\",\"datePublished\":\"2016-07-07T12:00:53+00:00\",\"dateModified\":\"2023-11-09T13:23:43+00:00\",\"description\":\"In this example we shall show you how to create RESTful APIs using\u00a0Grails. Exposing your application functionality to other applications is always\",\"breadcrumb\":{\"@id\":\"https:\/\/examples.javacodegeeks.com\/jvm-languages\/groovy\/grails\/grails-rest-example\/#breadcrumb\"},\"inLanguage\":\"en-US\",\"potentialAction\":[{\"@type\":\"ReadAction\",\"target\":[\"https:\/\/examples.javacodegeeks.com\/jvm-languages\/groovy\/grails\/grails-rest-example\/\"]}]},{\"@type\":\"ImageObject\",\"inLanguage\":\"en-US\",\"@id\":\"https:\/\/examples.javacodegeeks.com\/jvm-languages\/groovy\/grails\/grails-rest-example\/#primaryimage\",\"url\":\"https:\/\/examples.javacodegeeks.com\/wp-content\/uploads\/2015\/09\/grails-logo.jpg\",\"contentUrl\":\"https:\/\/examples.javacodegeeks.com\/wp-content\/uploads\/2015\/09\/grails-logo.jpg\",\"width\":150,\"height\":150},{\"@type\":\"BreadcrumbList\",\"@id\":\"https:\/\/examples.javacodegeeks.com\/jvm-languages\/groovy\/grails\/grails-rest-example\/#breadcrumb\",\"itemListElement\":[{\"@type\":\"ListItem\",\"position\":1,\"name\":\"Home\",\"item\":\"https:\/\/examples.javacodegeeks.com\/\"},{\"@type\":\"ListItem\",\"position\":2,\"name\":\"JVM Languages\",\"item\":\"https:\/\/examples.javacodegeeks.com\/category\/jvm-languages\/\"},{\"@type\":\"ListItem\",\"position\":3,\"name\":\"Groovy\",\"item\":\"https:\/\/examples.javacodegeeks.com\/category\/jvm-languages\/groovy\/\"},{\"@type\":\"ListItem\",\"position\":4,\"name\":\"Grails\",\"item\":\"https:\/\/examples.javacodegeeks.com\/category\/jvm-languages\/groovy\/grails\/\"},{\"@type\":\"ListItem\",\"position\":5,\"name\":\"Grails REST Example\"}]},{\"@type\":\"WebSite\",\"@id\":\"https:\/\/examples.javacodegeeks.com\/#website\",\"url\":\"https:\/\/examples.javacodegeeks.com\/\",\"name\":\"Java Code Geeks\",\"description\":\"Java Examples and Code Snippets\",\"publisher\":{\"@id\":\"https:\/\/examples.javacodegeeks.com\/#organization\"},\"alternateName\":\"JCG\",\"potentialAction\":[{\"@type\":\"SearchAction\",\"target\":{\"@type\":\"EntryPoint\",\"urlTemplate\":\"https:\/\/examples.javacodegeeks.com\/?s={search_term_string}\"},\"query-input\":{\"@type\":\"PropertyValueSpecification\",\"valueRequired\":true,\"valueName\":\"search_term_string\"}}],\"inLanguage\":\"en-US\"},{\"@type\":\"Organization\",\"@id\":\"https:\/\/examples.javacodegeeks.com\/#organization\",\"name\":\"Exelixis Media P.C.\",\"url\":\"https:\/\/examples.javacodegeeks.com\/\",\"logo\":{\"@type\":\"ImageObject\",\"inLanguage\":\"en-US\",\"@id\":\"https:\/\/examples.javacodegeeks.com\/#\/schema\/logo\/image\/\",\"url\":\"https:\/\/examples.javacodegeeks.com\/wp-content\/uploads\/2022\/06\/exelixis-logo.png\",\"contentUrl\":\"https:\/\/examples.javacodegeeks.com\/wp-content\/uploads\/2022\/06\/exelixis-logo.png\",\"width\":864,\"height\":246,\"caption\":\"Exelixis Media P.C.\"},\"image\":{\"@id\":\"https:\/\/examples.javacodegeeks.com\/#\/schema\/logo\/image\/\"},\"sameAs\":[\"https:\/\/www.facebook.com\/javacodegeeks\",\"https:\/\/x.com\/javacodegeeks\"]},{\"@type\":\"Person\",\"@id\":\"https:\/\/examples.javacodegeeks.com\/#\/schema\/person\/553eb8f56e9ffb76e6bcc85d6157fc91\",\"name\":\"Ashraf Sarhan\",\"image\":{\"@type\":\"ImageObject\",\"inLanguage\":\"en-US\",\"@id\":\"https:\/\/examples.javacodegeeks.com\/#\/schema\/person\/image\/\",\"url\":\"https:\/\/examples.javacodegeeks.com\/wp-content\/uploads\/2024\/04\/cropped-ashraf_sarhan_photo-96x96.jpg\",\"contentUrl\":\"https:\/\/examples.javacodegeeks.com\/wp-content\/uploads\/2024\/04\/cropped-ashraf_sarhan_photo-96x96.jpg\",\"caption\":\"Ashraf Sarhan\"},\"description\":\"Ashraf Sarhan is a passionate software engineer, an open source enthusiast, has a Bsc. degree in Computer and Information Systems from Alexandria University. He is experienced in building large, scalable and distributed enterprise applications\/service in multiple domains. He also has a keen interest in JavaEE, SOA, Agile and Big Data technologies.\",\"sameAs\":[\"http:\/\/www.javacodegeeks.com\",\"https:\/\/www.facebook.com\/ashraf.sar7an\",\"https:\/\/eg.linkedin.com\/in\/ashrafsarhan\",\"https:\/\/x.com\/http:\/\/twitter.com\/ashraf_sarhan\"],\"url\":\"https:\/\/examples.javacodegeeks.com\/author\/ashraf-sarhan\/\"}]}<\/script>\n<!-- \/ Yoast SEO plugin. -->","yoast_head_json":{"title":"Grails REST Example - Java Code Geeks","description":"In this example we shall show you how to create RESTful APIs using\u00a0Grails. Exposing your application functionality to other applications is always","robots":{"index":"index","follow":"follow","max-snippet":"max-snippet:-1","max-image-preview":"max-image-preview:large","max-video-preview":"max-video-preview:-1"},"canonical":"https:\/\/examples.javacodegeeks.com\/jvm-languages\/groovy\/grails\/grails-rest-example\/","og_locale":"en_US","og_type":"article","og_title":"Grails REST Example - Java Code Geeks","og_description":"In this example we shall show you how to create RESTful APIs using\u00a0Grails. Exposing your application functionality to other applications is always","og_url":"https:\/\/examples.javacodegeeks.com\/jvm-languages\/groovy\/grails\/grails-rest-example\/","og_site_name":"Examples Java Code Geeks","article_publisher":"https:\/\/www.facebook.com\/javacodegeeks","article_author":"https:\/\/www.facebook.com\/ashraf.sar7an","article_published_time":"2016-07-07T12:00:53+00:00","article_modified_time":"2023-11-09T13:23:43+00:00","og_image":[{"width":150,"height":150,"url":"https:\/\/examples.javacodegeeks.com\/wp-content\/uploads\/2015\/09\/grails-logo.jpg","type":"image\/jpeg"}],"author":"Ashraf Sarhan","twitter_card":"summary_large_image","twitter_creator":"@http:\/\/twitter.com\/ashraf_sarhan","twitter_site":"@javacodegeeks","twitter_misc":{"Written by":"Ashraf Sarhan","Est. reading time":"4 minutes"},"schema":{"@context":"https:\/\/schema.org","@graph":[{"@type":"Article","@id":"https:\/\/examples.javacodegeeks.com\/jvm-languages\/groovy\/grails\/grails-rest-example\/#article","isPartOf":{"@id":"https:\/\/examples.javacodegeeks.com\/jvm-languages\/groovy\/grails\/grails-rest-example\/"},"author":{"name":"Ashraf Sarhan","@id":"https:\/\/examples.javacodegeeks.com\/#\/schema\/person\/553eb8f56e9ffb76e6bcc85d6157fc91"},"headline":"Grails REST Example","datePublished":"2016-07-07T12:00:53+00:00","dateModified":"2023-11-09T13:23:43+00:00","mainEntityOfPage":{"@id":"https:\/\/examples.javacodegeeks.com\/jvm-languages\/groovy\/grails\/grails-rest-example\/"},"wordCount":760,"commentCount":1,"publisher":{"@id":"https:\/\/examples.javacodegeeks.com\/#organization"},"image":{"@id":"https:\/\/examples.javacodegeeks.com\/jvm-languages\/groovy\/grails\/grails-rest-example\/#primaryimage"},"thumbnailUrl":"https:\/\/examples.javacodegeeks.com\/wp-content\/uploads\/2015\/09\/grails-logo.jpg","keywords":["Grails","REST"],"articleSection":["Grails"],"inLanguage":"en-US","potentialAction":[{"@type":"CommentAction","name":"Comment","target":["https:\/\/examples.javacodegeeks.com\/jvm-languages\/groovy\/grails\/grails-rest-example\/#respond"]}]},{"@type":"WebPage","@id":"https:\/\/examples.javacodegeeks.com\/jvm-languages\/groovy\/grails\/grails-rest-example\/","url":"https:\/\/examples.javacodegeeks.com\/jvm-languages\/groovy\/grails\/grails-rest-example\/","name":"Grails REST Example - Java Code Geeks","isPartOf":{"@id":"https:\/\/examples.javacodegeeks.com\/#website"},"primaryImageOfPage":{"@id":"https:\/\/examples.javacodegeeks.com\/jvm-languages\/groovy\/grails\/grails-rest-example\/#primaryimage"},"image":{"@id":"https:\/\/examples.javacodegeeks.com\/jvm-languages\/groovy\/grails\/grails-rest-example\/#primaryimage"},"thumbnailUrl":"https:\/\/examples.javacodegeeks.com\/wp-content\/uploads\/2015\/09\/grails-logo.jpg","datePublished":"2016-07-07T12:00:53+00:00","dateModified":"2023-11-09T13:23:43+00:00","description":"In this example we shall show you how to create RESTful APIs using\u00a0Grails. Exposing your application functionality to other applications is always","breadcrumb":{"@id":"https:\/\/examples.javacodegeeks.com\/jvm-languages\/groovy\/grails\/grails-rest-example\/#breadcrumb"},"inLanguage":"en-US","potentialAction":[{"@type":"ReadAction","target":["https:\/\/examples.javacodegeeks.com\/jvm-languages\/groovy\/grails\/grails-rest-example\/"]}]},{"@type":"ImageObject","inLanguage":"en-US","@id":"https:\/\/examples.javacodegeeks.com\/jvm-languages\/groovy\/grails\/grails-rest-example\/#primaryimage","url":"https:\/\/examples.javacodegeeks.com\/wp-content\/uploads\/2015\/09\/grails-logo.jpg","contentUrl":"https:\/\/examples.javacodegeeks.com\/wp-content\/uploads\/2015\/09\/grails-logo.jpg","width":150,"height":150},{"@type":"BreadcrumbList","@id":"https:\/\/examples.javacodegeeks.com\/jvm-languages\/groovy\/grails\/grails-rest-example\/#breadcrumb","itemListElement":[{"@type":"ListItem","position":1,"name":"Home","item":"https:\/\/examples.javacodegeeks.com\/"},{"@type":"ListItem","position":2,"name":"JVM Languages","item":"https:\/\/examples.javacodegeeks.com\/category\/jvm-languages\/"},{"@type":"ListItem","position":3,"name":"Groovy","item":"https:\/\/examples.javacodegeeks.com\/category\/jvm-languages\/groovy\/"},{"@type":"ListItem","position":4,"name":"Grails","item":"https:\/\/examples.javacodegeeks.com\/category\/jvm-languages\/groovy\/grails\/"},{"@type":"ListItem","position":5,"name":"Grails REST Example"}]},{"@type":"WebSite","@id":"https:\/\/examples.javacodegeeks.com\/#website","url":"https:\/\/examples.javacodegeeks.com\/","name":"Java Code Geeks","description":"Java Examples and Code Snippets","publisher":{"@id":"https:\/\/examples.javacodegeeks.com\/#organization"},"alternateName":"JCG","potentialAction":[{"@type":"SearchAction","target":{"@type":"EntryPoint","urlTemplate":"https:\/\/examples.javacodegeeks.com\/?s={search_term_string}"},"query-input":{"@type":"PropertyValueSpecification","valueRequired":true,"valueName":"search_term_string"}}],"inLanguage":"en-US"},{"@type":"Organization","@id":"https:\/\/examples.javacodegeeks.com\/#organization","name":"Exelixis Media P.C.","url":"https:\/\/examples.javacodegeeks.com\/","logo":{"@type":"ImageObject","inLanguage":"en-US","@id":"https:\/\/examples.javacodegeeks.com\/#\/schema\/logo\/image\/","url":"https:\/\/examples.javacodegeeks.com\/wp-content\/uploads\/2022\/06\/exelixis-logo.png","contentUrl":"https:\/\/examples.javacodegeeks.com\/wp-content\/uploads\/2022\/06\/exelixis-logo.png","width":864,"height":246,"caption":"Exelixis Media P.C."},"image":{"@id":"https:\/\/examples.javacodegeeks.com\/#\/schema\/logo\/image\/"},"sameAs":["https:\/\/www.facebook.com\/javacodegeeks","https:\/\/x.com\/javacodegeeks"]},{"@type":"Person","@id":"https:\/\/examples.javacodegeeks.com\/#\/schema\/person\/553eb8f56e9ffb76e6bcc85d6157fc91","name":"Ashraf Sarhan","image":{"@type":"ImageObject","inLanguage":"en-US","@id":"https:\/\/examples.javacodegeeks.com\/#\/schema\/person\/image\/","url":"https:\/\/examples.javacodegeeks.com\/wp-content\/uploads\/2024\/04\/cropped-ashraf_sarhan_photo-96x96.jpg","contentUrl":"https:\/\/examples.javacodegeeks.com\/wp-content\/uploads\/2024\/04\/cropped-ashraf_sarhan_photo-96x96.jpg","caption":"Ashraf Sarhan"},"description":"Ashraf Sarhan is a passionate software engineer, an open source enthusiast, has a Bsc. degree in Computer and Information Systems from Alexandria University. He is experienced in building large, scalable and distributed enterprise applications\/service in multiple domains. He also has a keen interest in JavaEE, SOA, Agile and Big Data technologies.","sameAs":["http:\/\/www.javacodegeeks.com","https:\/\/www.facebook.com\/ashraf.sar7an","https:\/\/eg.linkedin.com\/in\/ashrafsarhan","https:\/\/x.com\/http:\/\/twitter.com\/ashraf_sarhan"],"url":"https:\/\/examples.javacodegeeks.com\/author\/ashraf-sarhan\/"}]}},"_links":{"self":[{"href":"https:\/\/examples.javacodegeeks.com\/wp-json\/wp\/v2\/posts\/39020","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/examples.javacodegeeks.com\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/examples.javacodegeeks.com\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/examples.javacodegeeks.com\/wp-json\/wp\/v2\/users\/24"}],"replies":[{"embeddable":true,"href":"https:\/\/examples.javacodegeeks.com\/wp-json\/wp\/v2\/comments?post=39020"}],"version-history":[{"count":0,"href":"https:\/\/examples.javacodegeeks.com\/wp-json\/wp\/v2\/posts\/39020\/revisions"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/examples.javacodegeeks.com\/wp-json\/wp\/v2\/media\/27333"}],"wp:attachment":[{"href":"https:\/\/examples.javacodegeeks.com\/wp-json\/wp\/v2\/media?parent=39020"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/examples.javacodegeeks.com\/wp-json\/wp\/v2\/categories?post=39020"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/examples.javacodegeeks.com\/wp-json\/wp\/v2\/tags?post=39020"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}