Skip to content

Instantly share code, notes, and snippets.

@chilismaug
Last active January 23, 2019 01:37
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save chilismaug/b08456798313808116ef1841a107ae5c to your computer and use it in GitHub Desktop.
Save chilismaug/b08456798313808116ef1841a107ae5c to your computer and use it in GitHub Desktop.
Spring getting started REST guides - compare parts of plain REST service guide with CORS flavored, more complete guide

STS gs Guides REST projects - Compare CORS vs plain

step REST gsg: CORS w/jQy client REST gsg: plain json
1 Create Resource Representation Class:
Greeting.java - POJO plus no arg constructor
Create Resource Representation Class:
Greeting.java- just a POJO
2 Create Resource Controller: GreetingController.java
- imports GetMapping , a shortcut for RequestMapping
- imports CrossOrigin
Create Resource Controller: GreetingController.java
- imports RequestMapping
3 /greeting route is mapped /greeting route is mapped
4 use @RestController annotation and default to using the Jackson Json converter use @RestController annotation and default to using the Jackson Json converter
5 add @CrossOrigin annotation above @Getmapping --
6 add global CORS config to GreetingController.java
7 Application.java Application.java
7 add global CORS config to Application.java --
9 Application.java: package it as a Boot app in a JAR Application.java: package it as a Boot app in a JAR
10 import 4 additional annotations to Application.java --
11 client prep: build html/js client using jQuery ajax client prep: nothing
12 client result: JSON data to Ajax client web page client result: a line of JSON
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment