Questions tagged [rest]

REST (Representational State Transfer) is a style of software architecture for distributed hypermedia systems such as the World Wide Web. It has increased in popularity relative to RPC architectures such as SOAP due to the intrinsic de-coupling of client from server that comes from having a uniform interface between heterogeneous systems.

(Not to be confused with or reST)

REST (REpresentational State Transfer) is an architectural style that uses identification of resources; manipulation of resources through representations; self-descriptive messages, and hypermedia as the engine of application state, to build distributed systems that are scalable and resilient to change.

The term was introduced and defined in 2000 by Roy Fielding in his doctoral dissertation. Fielding is one of the principal authors of the Hypertext Transfer Protocol (HTTP) specification versions 1.0 and 1.1.

In simple language, REST is an alternative to SOAP based web services. Where SOAP tries to model the exchange between client and server as calls to objects, REST tries to be faithful to the web domain.

Resources


Examples

A website's RESTful API is queried to find out information on a user, specified by a numerical ID.

Request Type: GET
http://www.api.website.com/users/12345

Returns, in a format for this example:

{"username" : "theuser",
 "userid"   :  12345,
 "first"    : "George",
 "last"     : "Washington"}

Question Index

Searching

REST search interface and the idempotency of GET
RESTful URL design for search
Best practice for implementing long-running searches with REST
Querystring in REST Resource url
What is the best way to create RESTful complex queries?
Question on REST conventions: retrieving information where lots of params are needed

Resource Design

How to design a RESTful collection resource?
RESTful design of a resource with binary states
RESTFful/Resource Oriented Design
RESTful resource - accepts a list of objects
RESTful API creates a globally unique resource
REST's 'resource communication mechanisms' and 'on-the-fly' improvement of a client's knowledge of them
How to move a REST resource?

Media Types

REST Media type explosion
Creating hypermedia links in a custom media-type
Custom content types: XLink vs. Atom

Books

Related tags

92665 questions
539
votes
5 answers

How to do a PUT request with cURL?

How do I test a RESTful PUT (or DELETE) method using cURL?
John
  • 13,125
  • 14
  • 52
  • 73
524
votes
9 answers

400 vs 422 response to POST of data

I'm trying to figure out what the correct status code to return on different scenarios with a "REST-like" API that I'm working on. Let's say I have an end point that allows POST'ing purchases in JSON format. It looks like this: { …
David S
  • 12,967
  • 12
  • 55
  • 93
521
votes
18 answers

Pass an array of integers to ASP.NET Web API?

I have an ASP.NET Web API (version 4) REST service where I need to pass an array of integers. Here is my action method: public IEnumerable GetCategories(int[] categoryIds){ // code to retrieve categories from database } And this is the…
Hemanshu Bhojak
  • 16,972
  • 16
  • 49
  • 64
507
votes
2 answers

How to implement REST token-based authentication with JAX-RS and Jersey

I'm looking for a way to enable token-based authentication in Jersey. I am trying not to use any particular framework. Is that possible? My plan is: A user signs up for my web service, my web service generates a token, sends it to the client, and…
DevOps85
  • 6,473
  • 6
  • 23
  • 42
485
votes
6 answers

REST API Best practice: How to accept list of parameter values as input

We are launching a new REST API and I wanted some community input on best practices around how we should have input parameters formatted: Right now, our API is very JSON-centric (only returns JSON). The debate of whether we want/need to return XML…
whatupwilly
  • 4,997
  • 3
  • 16
  • 5
477
votes
12 answers

RESTful URL design for search

I'm looking for a reasonable way to represent searches as a RESTful URLs. The setup: I have two models, Cars and Garages, where Cars can be in Garages. So my urls look like: /car/xxxx xxx == car id returns car with given id /garage/yyy yyy =…
Parand
  • 102,950
  • 48
  • 151
  • 186
466
votes
8 answers

When do I use path params vs. query params in a RESTful API?

I want to make my RESTful API very predictable. What is the best practice for deciding when to make a segmentation of data using the URI rather than by using query params. It makes sense to me that system parameters that support pagination, sorting,…
cosbor11
  • 14,709
  • 10
  • 54
  • 69
458
votes
14 answers

Best practice to return errors in ASP.NET Web API

I have concerns on the way that we returns errors to client. Do we return error immediately by throwing HttpResponseException when we get an error: public void Post(Customer customer) { if (string.IsNullOrEmpty(customer.Name)) { …
cuongle
  • 74,024
  • 28
  • 151
  • 206
455
votes
9 answers

What's an appropriate HTTP status code to return by a REST API service for a validation failure?

I'm currently returning 401 Unauthorized whenever I encounter a validation failure in my Django/Piston based REST API application. Having had a look at the HTTP Status Code Registry I'm not convinced that this is an appropriate code for a validation…
michaeljoseph
  • 7,023
  • 5
  • 26
  • 27
453
votes
13 answers

What is the difference between HTTP and REST?

After reading a lot about the differences between REST and SOAP, I got the impression that REST is just another word for HTTP. Can someone explain what functionality REST adds to HTTP? Note: I'm not looking for a comparison of REST versus SOAP.
Dimitri C.
  • 21,861
  • 21
  • 85
  • 101
446
votes
17 answers

How do I make calls to a REST API using C#?

This is the code I have so far: public class Class1 { private const string URL = "https://sub.domain.com/objects.json?api_key=123"; private const string DATA = @"{""object"":{""name"":""Name""}}"; static void…
NullVoxPopuli
  • 61,906
  • 73
  • 206
  • 352
436
votes
6 answers

REST / SOAP endpoints for a WCF service

I have a WCF service and I want to expose it as both a RESTfull service and as a SOAP service. Anyone has done something like this before?
Wessam Zeidan
  • 4,531
  • 3
  • 18
  • 7
419
votes
10 answers

How to use cURL to send Cookies?

I read that sending cookies with cURL works, but not for me. I have a REST endpoint like this: class LoginResource(restful.Resource): def get(self): print(session) if 'USER_TOKEN' in session: return 'OK' …
daydreamer
  • 87,243
  • 191
  • 450
  • 722
411
votes
8 answers

What are best practices for REST nested resources?

As far as I can tell each individual resource should have only one canonical path. So in the following example what would good URL patterns be? Take for example a rest representation of Companies. In this hypothetical example, each company owns 0…
Wes
  • 6,697
  • 6
  • 34
  • 59
400
votes
3 answers

What's the best way to parse a JSON response from the requests library?

I'm using the python requests module to send a RESTful GET to a server, for which I get a response in JSON. The JSON response is basically just a list of lists. What's the best way to coerce the response to a native Python object so I can either…
felix001
  • 15,341
  • 32
  • 94
  • 121