How to create a RESTful interface for the following scenario?
I have a resource called Media, which has a number of properties (Name, MediaType, MetaData, File). The Media resource also holds a pysical file. Now some of the details of the Media resource (MetaData), are gathered from the file. In my system, I am able to work in 2 ways.
1) Create a Media resource, setting Name and MediaType, then post a File to it (which updates the meta data).
I currently have this working in my web service as follows:
POST /rest/media (Creates and returns a Media resource)
GET /rest/media/{id} (Gets a specific Med开发者_JAVA百科ia resource) PUT /rest/media/{id}/file (Uploads the file, and updates the Media resource) GET /rest/media/{id}/file (Gets the uploaded file)2) Upload a file, which automatically creates a Media resource, setting the Name to the file name, and automatically working out the MediaType from the file extension.
This is the scenario I need help architecting. I'd like to support both methods, but am unsure how to map this to a RESTful URL structure.
I'm open to general "RESTful" suggestions, but if you have an specific suggestions based on OpenRasta, that would be ideal.
I have good news for you. Not only has this already been designed for you, it's also a standard that has been implemented by many existing clients and servers: http://bitworking.org/projects/atom/rfc5023.html#media-link-entries
精彩评论