Skip to content

Instantly share code, notes, and snippets.

@joshlong
Created March 13, 2013 18:25
Show Gist options
  • Select an option

  • Save joshlong/5154769 to your computer and use it in GitHub Desktop.

Select an option

Save joshlong/5154769 to your computer and use it in GitHub Desktop.
how to properly send a header and a status code
@RequestMapping(value = USER_COLLECTION_URL, method = RequestMethod.POST)
public ResponseEntity<User> registerUser(@RequestParam("username") String username,
@RequestParam("password") String password,
@RequestParam("firstname") String fn,
@RequestParam("lastname") String ln,
@RequestParam("imported") boolean importedFromServiceProvider,
UriComponentsBuilder componentsBuilder) throws Throwable {
User user = this.userService.createOrGet(username, password, fn, ln, importedFromServiceProvider);
UriComponents uriComponents = componentsBuilder.path(USER_COLLECTION_ENTRY_URL).buildAndExpand(user.getId());
HttpHeaders httpHeaders = new HttpHeaders();
httpHeaders.setLocation(uriComponents.toUri());
return new ResponseEntity<User>(user, httpHeaders, HttpStatus.CREATED);
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment