Defining and representing your resources in your RESTful API

This short article is the second one of the series of articles I’m writing about pragmatic decisions for your RESTful API. It follows the introduction of this series of articles.

Defining your resources: use nouns, not verbs

One of the basic principles of REST is that it is based on resources vs actions. The first thing you should do when you design a RESTful API is to define your basic resources. One that you will most probably have is a user resource, probably with attributes like first name, last name etc…

At this stage, it doesn’t make sense to try to build an exhaustive list of all the attributes of all your resources, but try to build at least a list of your resources, using nouns (not verbs)

Representing your resources : use JSON

This is an easy choice at least. JSON is definitely the way to go, and a clear winner over XML, easier to read, lighter to transfer and easily readable by Javascript, which is becoming a very popular language for building RESTful APIs. Therefore, use XML only if you have specific requirements, otherwise, use JSON.

The next article will focus on using the correct HTTP methods and HTTP status codes.

This series of articles about Restful API design is also available as an eBook on Amazon, if you need it in a handy format.

Originally published at https://www.gvj-web.com on March 15, 2018.

--

--

Get the Medium app

A button that says 'Download on the App Store', and if clicked it will lead you to the iOS App store
A button that says 'Get it on, Google Play', and if clicked it will lead you to the Google Play store