I am working on a tagging application to explore REST and Dropwizard.
Images can be uploaded and associated with tags. CRUD operation on those resources. Here the 2 resources are - image and tag. I am following the collections pattern in designing the rest endpoints . The DB schema of the mini application are as follows -
create table images(
id BIGINT NOT NULL AUTO_INCREMENT,
url VARCHAR(100) NOT NULL,
isActive BOOLEAN default true,
description BLOB NOT NULL,
creation_time TIMESTAMP default now(),
updation_time TIMESTAMP default now(),
PRIMARY KEY ( id )
);
create table tags(
id BIGINT NOT NULL AUTO_INCREMENT,
description BLOB NOT NULL,
is_active BOOLEAN default true,
creation_time TIMESTAMP default now(),
updation_time TIMESTAMP default now(),
PRIMARY KEY( id )
);
create table images_tags(
id BIGINT NOT NULL AUTO_INCREMENT,
image_id BIGINT NOT NULL,
tag_id BIGINT NOT NULL,
is_active BOOLEAN default true,
association_time TIMESTAMP default now(),
PRIMARY KEY( id ),
CONSTRAINT images_tags_uc UNIQUE (image_id,tag_id,is_active),
FOREIGN KEY (image_id) REFERENCES images(id),
FOREIGN KEY (tag_id) REFERENCES tags(id)
)
The endpoints designed are as follows -
GET /images
GET /images/{id}
GET /tags
GET /tags/{id}
POST /images - creation of a new image- body will contain the tags associated at image upload/creation in the system.
POST /tags - creation of a new tag
PUT /tags/{id} - update a tag
PUT /images/{id} - update a image
DELETE /tags/{id}
DELETE /images/{id}
GET /search/tags?query="ab*"&startIndex=0&limit=20 - search tags starting with ab
Now the use-case where I am stuck about the endpoint design.
A uploaded image can change the tag association . lets say image I1 at creation time got associated with tags t1,t2. Later user wants to remove t2 tag and add tag - t3,t4 from available tags to the image. How should this action/use-case be supported by API following REST principles.
My design -
PUT /images/{id}/tags/associate
{
"addedTags" :[t3,t4],
"removeTags" : [t2]
}
*My question is that is the above endpoint a good way of REST api design. If not what should the endpoint look like ? *