This screencast provides an introduction to the new Grails 2.3 REST support for creating APIs. This is the first in a series of screencasts that I hope to publish focused on building APIs with Grails 2.3.
This first one covers the different ways to create RESTful controllers as well as how to quickly modify the response. Future screencasts will cover more advanced topics like implementing custom renderers, versioning and integration with Spring Security OAuth. If you have additional topic suggestions, please let me know in the comments! Thanks for watching!
The GR8CONF US Hackathon is this Sunday, July 21st! If you have not registered yet, please sign up at the ChallengePost site! It officially starts at 6pm, but feel free to come to Target Plaza Commons at 1011 Nicollet Mall in downtown Minneapolis anytime after the GR8CONF workshops. You do not have to compete in the hackathon to attend the event. You are certainly welcome to just come hang-out at the hackathon. It will be a great opportunity to mingle with fellow Groovy enthusiasts and network with others in the community! There will be free food and beverages at the event. Hope to see you Sunday!
For those competing in the hackathon, I thought I would publish some basic examples of using the Target APIs with Groovy for participants to have as a reference. The following GitHub repo has some Spock tests using the Guests, Locations and Products Target APIs. There are many other parameters to call these APIs with as well as additional APIs that you can use during the hackathon. This is meant to be just a quick sample you can use to validate that your API (and Target.com for OAuth) credentials are working.
When you arrive at the hackathon, you will register for a developer account and get your credentials to make API calls (developer accounts won’t be approved until the event even if you register now). After you register and your developer account is approved at the hackathon by the Target API team, login to the developer portal and create an application. You will then be provided API keys for that application in the portal. Put the Consumer Key, Secret Key and User ID (the username you logged into the developer portal with) into Target.java (the Secret Key isn’t actually needed for the API tests we’ll be running though, just the Consumer Key and User ID). Next, you’ll need to create a Target.com guest account if you don’t already have an account on Target.com. Once registered, put your username and password into the “when” block in GuestsSpec.groovy. In that same file, put in your first name, last name and email that you used when registering on Target.com into the “then” block. With all this in place, now it’s time to run the tests via Gradle to make sure everything works! There is no need to have anything else installed but a JDK to run the test-suite as it leverages the Gradle wrapper.
./gradlew test (linux, osx)
gradlew.bat test (windows)
If all tests pass, you’re all set to start using any of the APIs documented in the Target developer portal at the hackathon! If you encounter any problems running these tests, please find a Target API team member to help you. I hope you have fun playing with Target APIs at the GR8CONF US Hackathon!
Target will be hosting a hackathon as part of the GR8CONF US 2013 conference and today I would like to announce that registration is officially open for the event! Target is very excited to be hosting this hackathon for conference attendees as well as being an official sponsor of the conference. To register, please visit the link below to access the hackathon website on ChallengePost. Please register as soon as possible so we can plan accordingly! API documentation and a developer API key will be provided to all attendees at the event.
Registration for the hackathon is open until 5:00 p.m. CDT on July 17, 2013. You must be registered for the hackathon on ChallengePost and be a registered GR8CONF US attendee by this time to enter Target Plaza Commons for the event. There will be no exceptions.
There is going to be a slight change from what was previously announced for the hackathon. The competition is going to solely focus on utilizing Target APIs with GR8 technologies. Previously I stated that there would also be an open-source bug race, but this has been dropped. The bug race was simply creating too many challenges from a competition standpoint. Most people I have discussed the hackathon with have expressed much more interest in playing with Target data than the bug race anyway. I hope attendees understand and are just as excited about the hackathon!
I am using ChallengePost to power this hackathon! The platform is designed to support hackathons and provide exposure to developers and the projects they build. It’s completely free and helps promote events to the larger developer community. I worked with Richard at ChallengePost (email@example.com) for the GR8CONF hackathon. Feel free to reach out to him know if you want to use ChallengePost yourself!
I have been developing some APIs with Grails lately as opposed to traditional web apps. I’m going to be giving a talk at GR8CONF US this summer about this topic too.
So, I thought it would be fun to create a screencast with some tips for getting started building APIs with Grails! The screencast covers content types, API URL mappings, customizing JSON output with marshallers and even Rob Fletcher’s GSON plugin. I unfortunately recorded this screencast on a MacBookPro as opposed to an iMac and there’s some background noise because of the MBP fan. First and last time I use a MBP for a screencast, ha! Hopefully it doesn’t distract from the content too much. Thanks for watching!
The sample app built in the screencast is located on GitHub.
As you might have already heard, Target will be hosting a hackathon as part of the GR8CONF US 2013 conference! If you are not aware of GR8CONF US, it’s a technology conference focused on the Groovy ecosystem (Groovy, Grails, Griffon, Gradle, Spock, Geb, GVM, GPars, Gaelyk, Ratpack and CodeNarc). It will be hosted at the Minneapolis Convention Center on July 21-23. Today, I would like to share some details about the hackathon! It will take place Sunday night after the workshops on July 21st from 6:00pm to 10:00pm at the new Target Plaza Commons at 1011 Nicollet Mall in downtown Minneapolis and all conference attendees are welcome to join at no additional charge!
This isn’t just a regular hackathon though as it will instead be a competition with Target gift card prizes for the top GR8 hackers! The competition will be focused on two categories with $2,400 in total gift card prizes (1st place: $500, 2nd place: $400, 3rd place: $300 in each category). The official contest rules for how the entries will be judged will be published closer to the event. Here is a quick overview of the two categories though:
The first category is a bug race on the various open-source GR8 technologies. There will be various points awarded for the types of bugs found, solutions identified, pull requests opened and of course commits made! The judging for this category will be very quantitative and the winners will simply be the ones that get the most points.
The second category will focus on utilizing Target APIs with GR8 technologies. This event will mark the first alpha release of public Target APIs and we are excited to gather feedback from the GR8 developer community! These APIs are used by various applications at Target today. The judging for this category will be qualitative and the Target API team will select the winners based on creativity, APIs used and potential relevance to Target guests.
Target will be providing appetizers and refreshments for participants throughout the hackathon as well as have representation from various Target teams if anybody is interested in learning more about technology opportunities at Target.
Target is very excited to be a sponsor of GR8CONF US for 2013 and to host this hackathon as part of the conference for attendees! I look forward to providing you more details about the hackathon as we get closer to the event. I also will publish an official registration form soon! I hope that as many conference attendees as possible plan to attend and hack at the GR8CONF US hackathon!
Disclaimer: You must be registered as a conference attendee before Wednesday, July 17th at 5pm CST to be able to enter Target Plaza Commons for the event. There will be no exceptions. As per Target policy, all attendee names need to be known before the event. Target employees are welcome to participate in the hackathon, but are not eligible to win the gift cards. All participants will need to fill out the registration form and agree to the contest rules. The contest for gift cards starts and ends with the hackathon: July 21st from 6:00pm to 10:00pm.
I gave a talk today called “Contributing Back To Grails” at GR8CONF. You can view the presentation slides via the links below. There is a Keynote file and the slides have embedded screencasts that demo the various steps of actually doing a code contribution. I also posted the slides on SlideShare, but the embedded screencasts don’t work unfortunately on SlideShare. As part of the talk, I also created three pull requests for Grails!
Have you used PJAX yet (PushState + AJAX = PJAX)? It’s a pretty slick way to make AJAX partial updates a lot better compared to the regular g:remoteLink tag. The primary benefits are you don’t break the back button functionality and it updates the URL!
The key to implementing PJAX is that you need to have a “chrome-less” view for PJAX requests. This means the view can’t have the main.gsp layout applied to it (or whatever your layout is called). There are a number of different ways you could do this. First, you could simply look for the HTTP header that PJAX adds to each request called X-Pjax and then apply a different layout in the controller (or no layout at all). The approach I decided to take was a little different though. I decided that I didn’t want to modify any controllers and instead do it at the framework level. I also didn’t want to modify any views that already have the meta.layout (<meta name=”layout” content=”main”/>). My solution was to extend GrailsLayoutDecoratorMapper with my own new class called PjaxDecoratorMapper. I was originally going to create a Grails PJAX plugin to take care of this, but you need to modify sitemesh.xml in order to register this new decorator and I don’t believe there currently is any programmatic way to do that (like you can with web.xml). Also, the way that I’m implementing PJAX is certainly not the only way in a Grails app so I’m not sure how much value a plugin would even really provide. If people like this approach and it provides value, I’m certainly open to creating a plugin though. Let me know! So, let’s dive in!
Edit grails-app/conf/ApplicationResources.groovy to look like the following:
Next, we need to create a layout that will only be used for our PJAX requests.
Create a new grails-app/views/layouts/pjax.gsp that looks like this:
As you can see, all this layout is doing is rendering the body wrapped in a div called main. You can obviously call this div whatever you want or have multiple layouts for different divs that you want to use PJAX with if needed. For my needs, I simply wanted to always update one common area with PJAX, so just using one div for this met my needs.
Now let’s create our new decorator and configure it with sitemesh!
Create a new src/groovy/grails/pjax/PjaxDecoratorMapper.groovy file that looks like this:
Then modify the decorator-mappers part of web-app/WEB-INF/sitemesh.xml so it looks like this:
In the screencast below, I will now demonstrate using this PJAX setup in a sample application! You can download all the source for this screencast on GitHub: https://github.com/gr8casts/pjaxsample.
I hope you enjoyed this post about using PJAX in Grails! Please let me know in the comments if you have any suggestions for ways to improve PJAX usage in Grails and if you found this valuable or not. Thanks for reading & watching!
What’s more fun that building a Grails website? Building a Grails website that makes money of course, ha!
Back in December, I wrote a couple posts about using Stripe with Grails to process credit cards and released some initial milestones for a plugin. Then last week, I released version 1.0 of the plugin. So, today I’m just providing a screencast to go along with that 1.0 release! Please let me know in the comments if you find the screencast valuable or not!
Yes, my API keys shown in the video have been invalidated.
It’s amazing how simple the jQuery libraries make complex front-end development. Then if you add in CoffeeScript, using jQuery is even better! In this screencast, I demonstrate creating a AJAX-enabled sortable-list in a Grails 2.0 application. Please let me know in the comments if you find the screen-cast valuable or not!
Have you used CoffeeScript yet? I just started playing with it and so far I think it’s great! In this screencast, I walk through how to use CoffeeScript in a Grails 2.0 application by building a simple “continuous-scrolling” page. Please let me know in the comments if you find the screen-cast valuable or not!