Questions tagged [restful-architecture]

RESTful, or representational state transfer, is a style of software architecture for distributed hypermedia systems such as the World Wide Web.

Representational state transfer (REST) is a style of software architecture for distributed hypermedia systems such as the World Wide Web.

REST attempts to describe architectures that use HTTP or similar protocols by constraining the interface to a set of well-known, standard operations (like GET, POST, PUT, DELETE for HTTP). Here, the focus is on interacting with stateless resources, rather than messages or operations.

1187 questions
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
89
votes
6 answers

Passing array in GET for a REST call

I have a url to fetch appointments for a user like this: /user/:userId/appointments How should the url look like if I want to get appointments for multiple users? should it be: /appointments?users=1d1,1d2.. Thanks, Chris.
ChrisOdney
  • 6,066
  • 10
  • 38
  • 48
71
votes
9 answers

How to combine websockets and http to create a REST API that keeps data up to date?

I am thinking about buildning a REST API with both websockets and http where I use websockets to tell the client that new data is available or provide the new data to the client directly. Here are some different ideas of how it could work: ws =…
David Berg
  • 1,958
  • 1
  • 21
  • 37
68
votes
4 answers

Proper way to consume data from RESTFUL API in django

I'm trying to learn django so while I have a current solution I'm not sure if it follows best practices in django. I would like to display information from a web api on my website. Let's say the api url is as…
user2694306
  • 3,832
  • 10
  • 47
  • 95
56
votes
4 answers

Why PATCH is neither safe nor idempotent?

I have trouble understanding why PATCH is not safe where PUT is. Aso the idempotent part - if I update a field of the resource, wouldn't that field return the same value after update?
Tony Vincent
  • 13,354
  • 7
  • 49
  • 68
45
votes
2 answers

How can Socket.io and RESTFul work together?

(I'm not familiar to RESTFul, please correct me if my concept is wrong) In RESTFul architecture, we map every action to an URL. If I click "post a article", may it's actually URL http://example.com/ and some data action=post&content=blahblah. If I…
Lai Yu-Hsuan
  • 27,509
  • 28
  • 97
  • 164
45
votes
5 answers

Can you use REST in PHP? If so how?

I am developing my own PHP Library and I would like to call RESTful web-services from my API. Can this be done in PHP and if so what are the basics in doing so?
Zeck
  • 6,433
  • 21
  • 71
  • 111
42
votes
10 answers

How can I make Laravel return a custom error for a JSON REST API

I'm developing some kind of RESTful API. When some error occurs, I throw an App::abort($code, $message) error. The problem is: I want him to throw a json formed array with keys "code" and "message", each one containing the above mentioned data.…
Dennis Braga
  • 1,448
  • 3
  • 20
  • 40
40
votes
4 answers

How to always append attributes to Laravel Eloquent model?

I was wondering how to always append some data to Eloquent model without the need of asking for it for example when getting Posts form database I want to append the user info for each user as: { id: 1 title: "My Post Title" body: "Some…
Mustafa Dwaikat
  • 3,392
  • 9
  • 27
  • 41
36
votes
3 answers

How to create a custom media type (application/vnd) for a RESTful web service?

I'm playing with REST right now and thought I properly implement HATEOAS just to get all concepts right. For that I want to create my own media types (application/vnd[...]+xml and application/vnd[...]+json). One first question: Does the media type…
JohnDoDo
  • 4,720
  • 8
  • 31
  • 47
35
votes
3 answers

best approach to design a rest web service with binary data to be consumed from the browser

I'm developing a json rest web service that will be consumed from a single web page app built with backbone.js This API will let the consumer upload files related to some entity, like pdf reports related to a project Googling around and doing some…
opensas
  • 60,462
  • 79
  • 252
  • 386
33
votes
3 answers

Should the PATCH method return all fields of the resource in the response body?

Should the PATCH method return all fields of the resource in the response body? Or should it return only updated fields? I'm reading this For example, if it returns only updated fields, the user could know which fields were updated in the server,…
Nigiri
  • 3,469
  • 6
  • 29
  • 52
31
votes
16 answers

file_get_contents('php://input') always returns an empty string

I'm building a PHP RESTful API, following this tutorial. The following function, which should return the data sent with the request when the 'put' method is used, returns null every time: file_get_contents('php://input'). I've even downloaded and…
Igor
  • 1,532
  • 4
  • 23
  • 44
30
votes
2 answers

HTTP status code when single request asks for too large resource or too many of them

Does somebody know which HTTP status code is the right one for the following situation? An anonymous client can request a range of items from a collection from RESTful API with GET /collection/?range_start=100&range_end=200. The example query…
Akseli Palén
  • 27,244
  • 10
  • 65
  • 75
30
votes
2 answers

Should a RESTful GET response return a resource's ID?

A number of the developers here are having a friendly (some would say religious) discussion about whether a GET request from a RESTful API should return the ID of the requested resource. Let's assume the following GET…
Armchair Bronco
  • 2,367
  • 4
  • 31
  • 44
1
2 3
79 80