3

Using HTTP POST method/AnyMethod If a client is sending some information like name, number etc in a representation to server and server is storing it to DB then here name and number is called a resource?

or we are creating a resource in server with the information what client gave?

then client will not have a resource at any time?

Ravana
  • 111
  • 9
  • I guess name, number etc are attributes of a resource, not a resource. Right? What resource are these attributes belonging to? – Philipp Jul 02 '20 at 21:35
  • So you are saying that a client will not have a resource but It will have some information and the representation of that resource will sent to server and a resource will be created in server? – Ravana Jul 02 '20 at 21:43
  • I think @maio290 pointed it out quite well. Whether number and name are considered as resources highly depends on the context. – Philipp Jul 04 '20 at 06:44

1 Answers1

3

Let's take a theoretical look at this:

resource = the intended conceptual target of a hypertext reference

[...]

The key abstraction of information in REST is a resource. Any information that can be named can be a resource: a document or image, a temporal service (e.g. "today's weather in Los Angeles"), a collection of other resources, a non-virtual object (e.g. a person), and so on. In other words, any concept that might be the target of an author's hypertext reference must fit within the definition of a resource. A resource is a conceptual mapping to a set of entities, not the entity that corresponds to the mapping at any particular point in time.

Source: Fielding, Roy Thomas. Architectural Styles and the Design of Network-based Software Architectures. Doctoral dissertation, University of California, Irvine, 2000 as referenced in RFC 7231.


In a brief interpretation that means that the resource is never any particular data but rather a mapping. Let's put it into something tangible:

GET /members
-> A resource called members (= set of entities) consisting out of username, e-mail address. 

Members is considered a resource because it describes what the set of entities represent and because I've decided so.


To answer your questions:

> name and number is called a resource?

Depends on the context. Are you storing the name and number alone and independent from each other? Then they are resources, if they are part of something else, the resource would be the thing the two values describe (e.g. contact information).

Since the concept is abstract, you may even define three resources here: names, contact information and numbers. As it said, any information can be a resource, but that's not a must. So you are free to decide what you call a resource and what not.

> or we are creating a resource in server with the information what
> client gave?

No. We are creating an entity within a resource. The resource was defined by you earlier.

> then client will not have a resource at any time?

To be frank, I am sitting over this question for quite some time now - the dissertation doesn't state something specific but from interpreting and understanding the abstract concept, I'd say no. The server always holds the state of a resource, the client just gets or modifies it, but never provides any resource itself.


Related Questions:

What are REST resources?

What is the difference between resource and resource representation in REST?

Community
  • 1
  • 1
maio290
  • 6,440
  • 1
  • 21
  • 38
  • can you answer this, please? https://stackoverflow.com/questions/62730975/is-rest-only-for-web-apis-if-not-then-what-other-systems-can-obey-rest-apart-f – Ravana Jul 04 '20 at 16:47