-
Notifications
You must be signed in to change notification settings - Fork 2
Expand file tree
/
Copy pathCustomers.cfc
More file actions
58 lines (45 loc) · 2.11 KB
/
Copy pathCustomers.cfc
File metadata and controls
58 lines (45 loc) · 2.11 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
<cfcomponent rest="true" restpath="customers" Name="Customers">
//GET Request to return customers
<cffunction name="get" access="remote" returnType="array" produces="application/json" httpmethod="GET">
<cfset customers = arrayNew(1)>
<cfset customers[1] = "Brian">
<cfset customers[2] = "Caroline">
<cfset customers[3] = "Noah">
<cfset customers[4] = "Elijah">
<cfset customers[5] = "Maverick">
<cfreturn customers />
</cffunction>
//GET Request to return customers
//This example accepts a path parameter and returns a single customer from the array
<cffunction name="getCustomer" access="remote" returnType="string" restPath="/orders/{customerID}" produces="application/json" httpmethod="GET">
<cfargument name="customerID" required="true"restargsource="Path" type="numeric"/>
<cfset customers = arrayNew(1)>
<cfset customers[1] = "Brian">
<cfset customers[2] = "Caroline">
<cfset customers[3] = "Noah">
<cfset customers[4] = "Elijah">
<cfset customers[5] = "Maverick">
<cfreturn customers[arguments.customerID] />
</cffunction>
//POST Request to write a new customer to the database
<cffunction name="post" access="remote" returnType="string" produces="application/json" httpmethod="POST">
//do database insert and validation logic
//return a successful message in the response
<cfset message = "Customer has been added.">
<cfreturn message>
</cffunction>
//PUT Request to edit a customer in the database
<cffunction name="put" access="remote" returnType="string" produces="application/json" httpmethod="PUT">
//do database update and validation logic
//return a successful message in the response
<cfset message = "Customer has been updated.">
<cfreturn message>
</cffunction>
//DELETE Request to remove a customer in the database
<cffunction name="delete" access="remote" returnType="string" produces="application/json" httpmethod="DELETE">
//do database delete and validation logic
//return a successful message in the response
<cfset message = "Customer has been deleted.">
<cfreturn message>
</cffunction>
</cfcomponent>