biziclop
biziclop

Reputation: 49794

How to represent a transformation in REST?

I want to write a service which takes an xml file (any xml file) and a couple of parameters as input and produces a transformed xml file as its output. So, for example, if I need a service that removes profanity, the parameters would be a severity treshold (on a scale from darn to f***) and the mode of transformation (f***ing, f@%%ing or flipping) The actual format of the xml is irrelevant, the output will always be the same format as the input. (Before you point out that this is a futile exercise: this isn't the service I actually want to build obviously.)

Although I've used REST-based services, I'm kind of new to designing them and I don't really know how to fit this in the resource/collection idiom and more importantly, how to make it really REST-like, avoiding WADLs and making the interface self-describing instead. Or is REST simply not the right tool for this?

Upvotes: 0

Views: 164

Answers (2)

Nick Briggs
Nick Briggs

Reputation: 166

This is a difficult question to answer from a REST perspective because the service you describe doesn't have any server-side resources - there's no server state to transfer in the requests and responses. All of the state is client-side. Traditionally, this would be handled by a GET, but you probably don't want to write an XML document into a query string.

Probably you be be best using the method suggested by Darrel Miller. POST to your desired endpoint with the document as the body, and have the response's body be the updated document.

Upvotes: 1

Darrel Miller
Darrel Miller

Reputation: 142202

From Httpbis :

POST is designed to allow a uniform method to cover the following functions: ... Providing a block of data, such as the result of submitting a form, to a data-handling process;

For example:

POST /ProfanityRemover?level=3
ContentType: application/xml

<Foo>
  <Blah>Damn</Blah>
</Foo>

=>
200 OK
ContentType: application/xml

<Foo>
  <Blah>Poop</Blah>
</Foo>

Upvotes: 1

Related Questions