Skip to content

Commit 0b56d2f

Browse files
author
Chris Latimer
committed
Accept-Version for API versioning
1 parent 70037c2 commit 0b56d2f

File tree

5 files changed

+77
-0
lines changed

5 files changed

+77
-0
lines changed

grails-app/conf/UrlMappings.groovy

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,5 +9,7 @@ class UrlMappings {
99

1010
"/"(view:"/index")
1111
"500"(view:'/error')
12+
"/phones"(version:'1.0', resources:"phone", namespace:'v1')
13+
"/phones"(version:'2.0', resources:"phone", namespace:'v2')
1214
}
1315
}
Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
package org.gmobile.v1
2+
3+
import grails.rest.RestfulController
4+
import org.gmobile.Phone
5+
6+
class PhoneController extends RestfulController<Phone> {
7+
static namespace = 'v1'
8+
static responseFormats = ['json', 'xml']
9+
10+
public PhoneController() {
11+
super(Phone)
12+
}
13+
14+
def index() {
15+
def obj = ["message" : "v1 has been deprecated"]
16+
respond obj
17+
}
18+
19+
}
Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
package org.gmobile.v2
2+
3+
import grails.converters.JSON
4+
import grails.rest.RestfulController
5+
import org.gmobile.Phone
6+
7+
class PhoneController extends RestfulController<Phone> {
8+
static namespace = 'v2'
9+
static responseFormats = ['json', 'xml']
10+
11+
public PhoneController() {
12+
super(Phone)
13+
}
14+
15+
}
Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
package gmobile
2+
3+
import grails.test.mixin.TestFor
4+
import org.gmobile.v1.PhoneController
5+
import spock.lang.Specification
6+
7+
/**
8+
* See the API for {@link grails.test.mixin.web.ControllerUnitTestMixin} for usage instructions
9+
*/
10+
@TestFor(PhoneController)
11+
class PhoneControllerSpec extends Specification {
12+
13+
def setup() {
14+
}
15+
16+
def cleanup() {
17+
}
18+
19+
void "test something"() {
20+
}
21+
}
Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
package org.gmobile.v2
2+
3+
import grails.test.mixin.TestFor
4+
import spock.lang.Specification
5+
6+
/**
7+
* See the API for {@link grails.test.mixin.web.ControllerUnitTestMixin} for usage instructions
8+
*/
9+
@TestFor(PhoneController)
10+
class PhoneControllerSpec extends Specification {
11+
12+
def setup() {
13+
}
14+
15+
def cleanup() {
16+
}
17+
18+
void "test something"() {
19+
}
20+
}

0 commit comments

Comments
 (0)