I have a REST API which has something like this:
GET /zones - lists all zones
{
"zones": [
{
"name": "zone 1",
"persons": [
0,
2,
3
],
"counter" : 3
},
{
"name": "zone 2",
"persons": [
1,
5
],
"counter" : 0
}
]
}
POST /zones - creates a new zone
{
"name": "zone 1",
"persons": [
0,
2,
3
]
}
DELETE /zones/:id
deletes a zone
PUT /zones/:id
updates a zone
and now, finally I have this:
GET /zones/increment_counter/:id
which increments the counter parameter of the zone.
I am using Angular and I am defining a factory for the Zone object, which should feed itself from this REST API.
I have seen this example and it fulfills almost of what I want, except the increment operation, which does not follow the RESTful guidelines.
I cannot modify the REST API so I have to deal with this. How should I handle these types of endpoints?
Also, should I use services or could I just define a method in my Zone factory (ex.: zone.incrementCounter()) which directly queries the server and increments the counter?
I am used to Java objects, where I just need to define getters and setters for a class and the class will access the server's endpoints under the hood.
What is the best approach to this?
See Question&Answers more detail:
os 与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…