A recent release of Do My Invoice was a minor update to add more documentation for the various resources used in the application. DMI is a REST application — well, at the very least, that was the initial design goal — so there are some basic access points for most system resources.
For example, you may call GET to request your user profile:
http://www.domyinvoice.com/resources/[username]/profile
Using CURL the request:
curl -X GET -u joebloggs:password http://www.domyinvoice.com/resources/joebloggs/profile
…will return something like…
<profile>
<username>joebloggs</username>
<email_address>joe@bloggs.com</email_address>
<first_name>Joe</first_name>
<last_name>Bloggs</last_name>
</profile>
Resources in DMI are self-describing, thus with the addition of a single parameter, you can view the documentation for that resource. Thus the url…
http://www.domyinvoice.com/resources/joebloggs/profile?help
…returns a list of the HTTP verbs accepted by the resource, basic description and more detailed information about each verb. If you don’t have an account (it’s free for the first month, by the way), you can see a static version of this help information here.
Another example, is the clients resource. You can GET a list of clients:
curl -X GET -u joebloggs:password http://www.domyinvoice.com/resources/joebloggs/clients
<clients>
<client id="76">
<client-name>test company</client-name>
<address1>address line 1</address1>
<address2>address line 2</address2>
<city>London</city>
<postcode>sa1 sa2</postcode>
<country>United Kingdom</country>
</client>
</clients>
A client can be added with the use of an HTTP PUT:
curl -X PUT -u joebloggs:password http://www.domyinvoice.com/resources/joebloggs/clients/test+company+2 -d @-
address_1=23+Wrights+Lane&address_2=Kensington&city=London&postcode=W8+6TA&country=GB¤cy_symbol=£¤cy_format=1&sales_tax_label=VAT&sales_tax=0.175
Which also returns the created client (assuming nothing went wrong):
<clients>
<client id="80">
<client-name>test+company+2</client-name>
<address1>23 Wrights Lane</address1>
<address2>Kensington</address2>
<city>London</city>
<postcode>W8 6TA</postcode>
<country>United Kingdom</country>
</client>
</clients>
Said client could then be deleted with the use of the DELETE verb:
curl -X DELETE -u joebloggs:password http://www.domyinvoice.com/resources/joebloggs/clients/test+company+2
The obvious advantage of using RESTful resources internally is that I’m effectively providing an external API for free — in other words, without requiring any additional development effort.

No comments yet.