Skip to content

Commit 0d45b71

Browse files
committed
API for RAML modularization article
1 parent 9815254 commit 0d45b71

25 files changed

Lines changed: 568 additions & 0 deletions
Lines changed: 119 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,119 @@
1+
#%RAML 1.0
2+
title: API for REST Services used in the RAML tutorials on Baeldung.com
3+
documentation:
4+
- title: Overview
5+
- content: |
6+
This document defines the interface for the REST services
7+
used in the popular RAML Tutorial series at Baeldung.com.
8+
- title: Disclaimer:
9+
- content: |
10+
All names used in this definition are purely fictional.
11+
Any similarities between the names used in this tutorial and those of real persons, whether living or dead, are merely coincidental.
12+
- title: Copyright
13+
- content: Copyright 2016 by Baeldung.com. All rights reserved.
14+
version: v1
15+
protocols: [ HTTPS ]
16+
baseUri: http://rest-api.baeldung.com/api/{version}
17+
mediaType: application/json
18+
securedBy: basicAuth
19+
securitySchemes:
20+
- basicAuth:
21+
description: Each request must contain the headers necessary for
22+
basic authentication
23+
type: Basic Authentication
24+
describedBy:
25+
headers:
26+
Authorization:
27+
description: |
28+
Used to send the Base64 encoded "username:password"
29+
credentials
30+
type: string
31+
responses:
32+
401:
33+
description: |
34+
Unauthorized. Either the provided username and password
35+
combination is invalid, or the user is not allowed to
36+
access the content provided by the requested URL.
37+
types:
38+
Foo: !include types/Foo.raml
39+
Bar: !include types/Bar.raml
40+
Error: !include types/Error.raml
41+
resourceTypes:
42+
- collection:
43+
usage: Use this resourceType to represent a collection of items
44+
description: A collection of <<resourcePathName|!uppercamelcase>>
45+
get:
46+
description: |
47+
Get all <<resourcePathName|!uppercamelcase>>,
48+
optionally filtered
49+
is: [ hasResponseCollection ]
50+
post:
51+
description: |
52+
Create a new <<resourcePathName|!uppercamelcase|!singularize>>
53+
is: [ hasRequestItem ]
54+
- item:
55+
usage: Use this resourceType to represent any single item
56+
description: A single <<typeName>>
57+
get:
58+
description: Get a <<typeName>> by <<resourcePathName>>
59+
is: [ hasResponseItem, hasNotFound ]
60+
put:
61+
description: Update a <<typeName>> by <<resourcePathName>>
62+
is: [ hasRequestItem, hasResponseItem, hasNotFound ]
63+
delete:
64+
description: Delete a <<typeName>> by <<resourcePathName>>
65+
is: [ hasNotFound ]
66+
responses:
67+
204:
68+
traits:
69+
- hasRequestItem:
70+
body:
71+
application/json:
72+
type: <<typeName>>
73+
- hasResponseItem:
74+
responses:
75+
200:
76+
body:
77+
application/json:
78+
type: <<typeName>>
79+
example: !include examples/<<typeName>>.json
80+
- hasResponseCollection:
81+
responses:
82+
200:
83+
body:
84+
application/json:
85+
type: <<typeName>>[]
86+
example: !include examples/<<typeName|!pluralize>>.json
87+
- hasNotFound:
88+
responses:
89+
404:
90+
body:
91+
application/json:
92+
type: Error
93+
example: !include examples/Error.json
94+
/foos:
95+
type: collection
96+
typeName: Foo
97+
get:
98+
queryParameters:
99+
name?: string
100+
ownerName?: string
101+
/{fooId}:
102+
type: item
103+
typeName: Foo
104+
/name/{name}:
105+
get:
106+
description: List all foos with a certain name
107+
typeName: Foo
108+
is: [ hasResponseCollection ]
109+
/bars:
110+
type: collection
111+
typeName: Bar
112+
/{barId}:
113+
type: item
114+
typeName: Bar
115+
/fooId/{fooId}:
116+
get:
117+
description: Get all bars for the matching fooId
118+
typeName: Bar
119+
is: [ hasResponseCollection ]
Lines changed: 50 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,50 @@
1+
#%RAML 1.0
2+
title: API for REST Services used in the RAML tutorials on Baeldung.com
3+
documentation:
4+
- title: Overview
5+
- content: |
6+
This document defines the interface for the REST services
7+
used in the popular RAML Tutorial series at Baeldung.com.
8+
- title: Disclaimer:
9+
- content: |
10+
All names used in this definition are purely fictional.
11+
Any similarities between the names used in this tutorial and those of real persons, whether living or dead, are merely coincidental.
12+
- title: Copyright
13+
- content: Copyright 2016 by Baeldung.com. All rights reserved.
14+
uses:
15+
mySecuritySchemes: !include libraries/security.raml
16+
myDataTypes: !include libraries/dataTypes.raml
17+
myResourceTypes: !include libraries/resourceTypes.raml
18+
myTraits: !include libraries/traits.raml
19+
version: v1
20+
protocols: [ HTTPS ]
21+
baseUri: http://rest-api.baeldung.com/api/{version}
22+
mediaType: application/json
23+
securedBy: [ mySecuritySchemes.basicAuth ]
24+
/foos:
25+
type: myResourceTypes.collection
26+
typeName: myDataTypes.Foo
27+
get:
28+
queryParameters:
29+
name?: string
30+
ownerName?: string
31+
/{fooId}:
32+
type: myResourceTypes.item
33+
typeName: myDataTypes.Foo
34+
/name/{name}:
35+
get:
36+
description: List all foos with a certain name
37+
typeName: myDataTypes.Foo
38+
is: [ myTraits.hasResponseCollection ]
39+
/bars:
40+
type: myResourceTypes.collection
41+
typeName: myDataTypes.Bar
42+
/{barId}:
43+
type: myResourceTypes.item
44+
typeName: myDataTypes.Bar
45+
/fooId/{fooId}:
46+
get:
47+
description: Get all bars for the matching fooId
48+
type: myResourceTypes.item
49+
typeName: myDataTypes.Bar
50+
is: [ myTraits.hasResponseCollection ]
Lines changed: 74 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,74 @@
1+
#%RAML 1.0
2+
title: API for REST Services used in the RAML tutorials on Baeldung.com
3+
documentation:
4+
- title: Overview
5+
- content: |
6+
This document defines the interface for the REST services
7+
used in the popular RAML Tutorial series at Baeldung.com.
8+
- title: Disclaimer:
9+
- content: |
10+
All names used in this definition are purely fictional.
11+
Any similarities between the names used in this tutorial and those of real persons, whether living or dead, are merely coincidental.
12+
- title: Copyright
13+
- content: Copyright 2016 by Baeldung.com. All rights reserved.
14+
version: v1
15+
protocols: [ HTTPS ]
16+
baseUri: http://rest-api.baeldung.com/api/{version}
17+
mediaType: application/json
18+
securedBy: [ basicAuth ]
19+
securitySchemes:
20+
- basicAuth:
21+
description: Each request must contain the headers necessary for
22+
basic authentication
23+
type: Basic Authentication
24+
describedBy:
25+
headers:
26+
Authorization:
27+
description: |
28+
Used to send the Base64 encoded "username:password"
29+
credentials
30+
type: string
31+
responses:
32+
401:
33+
description: |
34+
Unauthorized. Either the provided username and password
35+
combination is invalid, or the user is not allowed to
36+
access the content provided by the requested URL.
37+
types:
38+
Foo: !include types/Foo.raml
39+
Bar: !include types/Bar.raml
40+
Error: !include types/Error.raml
41+
resourceTypes:
42+
- collection: !include resourceTypes/collection.raml
43+
- item: !include resourceTypes/item.raml
44+
traits:
45+
- hasRequestItem: !include traits/hasRequestItem.raml
46+
- hasResponseItem: !include traits/hasResponseItem.raml
47+
- hasResponseCollection: !include traits/hasResponseCollection.raml
48+
- hasNotFound: !include traits/hasNotFound.raml
49+
/foos:
50+
type: collection
51+
typeName: Foo
52+
get:
53+
queryParameters:
54+
name?: string
55+
ownerName?: string
56+
/{fooId}:
57+
type: item
58+
typeName: Foo
59+
/name/{name}:
60+
get:
61+
description: List all foos with a certain name
62+
typeName: Foo
63+
is: [ hasResponseCollection ]
64+
/bars:
65+
type: collection
66+
typeName: Bar
67+
/{barId}:
68+
type: item
69+
typeName: Bar
70+
/fooId/{fooId}:
71+
get:
72+
description: Get all bars for the matching fooId
73+
typeName: Bar
74+
is: [ hasResponseCollection ]

‎raml/modularization/api.raml‎

Lines changed: 47 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,47 @@
1+
#%RAML 1.0
2+
title: Baeldung Foo REST Services API
3+
uses:
4+
security: !include libraries/security.raml
5+
version: v1
6+
protocols: [ HTTPS ]
7+
baseUri: http://rest-api.baeldung.com/api/{version}
8+
mediaType: application/json
9+
securedBy: [ security.basicAuth ]
10+
types:
11+
Foo: !include types/Foo.raml
12+
Bar: !include types/Bar.raml
13+
Error: !include types/Error.raml
14+
resourceTypes:
15+
- collection: !include resourceTypes/collection.raml
16+
- item: !include resourceTypes/item.raml
17+
traits:
18+
- hasRequestItem: !include traits/hasRequestItem.raml
19+
- hasResponseItem: !include traits/hasResponseItem.raml
20+
- hasResponseCollection: !include traits/hasResponseCollection.raml
21+
- hasNotFound: !include traits/hasNotFound.raml
22+
/foos:
23+
type: collection
24+
typeName: Foo
25+
get:
26+
queryParameters:
27+
name?: string
28+
ownerName?: string
29+
/{fooId}:
30+
type: item
31+
typeName: Foo
32+
/name/{name}:
33+
get:
34+
description: List all foos with a certain name
35+
typeName: Foo
36+
is: [ hasResponseCollection ]
37+
/bars:
38+
type: collection
39+
typeName: Bar
40+
/{barId}:
41+
type: item
42+
typeName: Bar
43+
/fooId/{fooId}:
44+
get:
45+
description: Get all bars for the matching fooId
46+
typeName: Bar
47+
is: [ hasResponseCollection ]
Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
{
2+
"id" : 1,
3+
"name" : "First Bar",
4+
"city" : "Austin",
5+
"fooId" : 2
6+
}
Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
[
2+
{
3+
"id" : 1,
4+
"name" : "First Bar",
5+
"city" : "Austin",
6+
"fooId" : 2
7+
},
8+
{
9+
"id" : 2,
10+
"name" : "Second Bar",
11+
"city" : "Dallas",
12+
"fooId" : 1
13+
},
14+
{
15+
"id" : 3,
16+
"name" : "Third Bar",
17+
"fooId" : 2
18+
}
19+
]
Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
{
2+
"message" : "Not found",
3+
"code" : 1001
4+
}
Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
{
2+
"id" : 1,
3+
"name" : "First Foo"
4+
}
Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
[
2+
{
3+
"id" : 1,
4+
"name" : "First Foo",
5+
"ownerName" : "Jack Robinson"
6+
},
7+
{
8+
"id" : 2,
9+
"name" : "Second Foo"
10+
},
11+
{
12+
"id" : 3,
13+
"name" : "Third Foo",
14+
"ownerName" : "Chuck Norris"
15+
}
16+
]
Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
#%RAML 1.0 Extension
2+
# File located at:
3+
# /extensions/en_US/additionalResources.raml
4+
masterRef: /api.raml
5+
usage: This extension defines additional resources for version 2 of the API.
6+
version: v2
7+
/foos:
8+
/bar/{barId}:
9+
get:
10+
description: |
11+
Get the foo that is related to the bar having barId = {barId}
12+
typeName: Foo
13+
queryParameters:
14+
barId?: integer
15+
typeName: Foo
16+
is: [ hasResponseItem ]

0 commit comments

Comments
 (0)