Stack Exchange Network

Stack Exchange network consists of 175 Q&A communities including Stack Overflow, the largest, most trusted online community for developers to learn, share their knowledge, and build their careers.

Visit Stack Exchange

New answers tagged

2

According to RFC 2616 (emphasis mine) Note that RFC 2616 is obsolete; it has been replaced by RFC 7230->RFC 7235. "Safe" is now defined in RFC 7231 Request methods are considered "safe" if their defined semantics are essentially read-only; i.e., the client does not request, and does not expect, any state change on the origin server as a result of ...


3

It is important to look at why we want to have safe and idempotent methods. ReST is an architectural style for large-scale information systems. Networks are inherently unreliable. So, you have to deal with things like lost, re-ordered, delayed, and duplicated messages, and strategies like caching. Idempotent methods allow you to repeat a request without ...


1

A background task is not a ressource as users or companies can be. Fielding, when defining REST, offered this definition of 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 ...


0

You can solve any computer programming problem with indirection, except too much indirection. I think I can see your thinking here. You want to move to a new application which will be a client of the web service but you don't want to get any of the old dated ickyness of the web service on your nice new clean application. So you want to protect it by ...


0

Adding new component to the system can add both an extra value and a cost. So situation with building the rest layer on top of the soap layer is similar to e.g. building rest layer on top of other rest layer. Example benefits: - Easier api / faster development against the rest api (if written correctly, might be opposite as well if coded incorrectly) ...


1

From the example what you seem to want to do is get all the users who have commented on any post in a particular thread. Generally if you find yourself doing complex queries to try and get a specific set of data that is a sign that what you actually need is just a new resource Something like GET /threads/{threadUuid}/all_users_that_commented and let the ...


0

It is a common pattern to combine multiple service behind a facade, especially if the link between your client and server would be a bottle neck (especially if it could be a mobile device). It might be worth checking out GraphQL before you completely re-invent the wheel yourself: https://graphql.org/


0

PATCH requests describe a set of operations to be applied to a resource, if you apply the same set of operations twice to the same resource, the result may not be the same. This is because defining the operations is up to you. In other words you have to define the merging rules. Remember a PATCH request could be used for patching resources in many different ...


1

I had different responses for the exceptions but then an Android dev complained that he needed to do some manual checks because of that. This is more important than any of the answer here. If you know the audience to whom the API is addressed you should hear them first. If they have different opinions, sit with them and allow them to expose their ...


3

The format of the response body for an error like 404 can be defined in the Content-Type in the header of the response (Content-Types can be more than just "json", you can define and document your own Content-Types that explain the actual format of the error. See here. Clients can then know what data they are getting back when something happens) This doesn'...


1

I am a regular user of the Stack Exchange API. It uses the same schema for errors and for successful responses, the wrapper. Of course, different fields will be filled; just compare the responses to the Site Information call for an existing site: https://api.stackexchange.com/2.2/info?site=softwareengineering and a non-existing one: https://api.stackexchange....


0

Dose it fetch the object with no change in state of the server? If not it is CRUD (not REST), and should use PUT. Representational State Transfer (REST) is a software architectural style that defines a set of constraints to be used for creating Web services. Web services that conform to the REST architectural style, called RESTful Web services (RWS), ...


0

The user is going to call this to place an order. They are going to want a response when they place this to know if it was placed or not. How do you handle waiting for command operations that you need a response to, and that response relies on waiting on other microservices potentially. You have two options. Firstly you can simply not return a response to ...


0

Since you are creating a new resource which you already have a URI for on the client end you should use PUT to create this resource. Your URL scheme should probably change though. /api/item/like has no connection to the user that linked the item. So how do you know which user liked it? A resource should have a unique URI. If you actually have lots and lots ...


0

No, this is decidedly against the intention of the GET operation. See this, in particular: In particular, the convention has been established that the GET and HEAD methods SHOULD NOT have the significance of taking an action other than retrieval. These methods ought to be considered "safe". This allows user agents to represent other methods, such as POST,...


0

Maybe this one will be considered a marginal answer, and I do not know all the details of this case, but I came to a conclusion that using a graph instead of "linear" API can save your day. The exact technology for a graph does not matter much (can be JSON-LD, RDF, GraphQL - you name it), but what is important is the ability to transfer subgraphs from one ...


1

To summarize, we need to create a new Job while also passing over the Project Name and CustomerAccount Name since we don't have access to the IDs to use. If the Project is not found, one is automatically created then assigned to the Job about to be created. Keep it simple. You don't need the project id or account id (I assume these are database ids). ...


0

Say I have done GET /students, to get a list of students, then I have to return the ID of the resources somewhere otherwise I am going to have no way to update them. Yes -- welcome to the world of hypermedia. More precisely, you need to return a link -- which means that your media types must clearly define how links are described in representations. For ...


0

Ok, here's some clever Typescript that solves this: interface HasId { id: string; } type Omit<T extends HasId, K extends keyof T> = Pick<T, Exclude<keyof T, K>>; type OptionalId<T extends HasId> = Omit<T, "id"> | T; And now, when you are creating your function createContract, then you create it with the signature ...


1

How would you handle this scenario? How would you do it with a web site? In HTML, you'd probably have a form, and using input controls you would collect the information that you need, and when the form was submitted the appropriate request would be created by the client and dispatched to the server. From the sound of things, the semantics of this are ...


1

It seems to me you're probably thinking of an operation where a resource (the "item") in your system is updated in some way, possibly within a transaction. This update can very well result in this entity moving from one table to another table. Another likely characteristic of your operation is that it's not idempotent; i.e. you cannot move an entity twice ...


0

Like most design decisions the answer is "it depends". Does updating a Foo usually require updating it's collection of Bar as well? Do they need to be updated in the same unit of work? Is Bar a value object? If the answer to one or more of these questions is "yes" then option 2 is probably the only course of action. Under these conditions you can consider ...


0

Reminder: REST doesn't care what spellings you use for your URI. As far as REST is concerned, it is perfectly reasonable for ACME Inc to be identified by /a05b7d44-8319-4609-bb17-6234b0a61e54, and for ACME Inc Employees to be identified by /2ae6f0a9-e8ea-4b0d-899e-39a11cd92fe1 and for ACME Inc Customers to be identified by /fcb01a22-8dd6-45d6-a489-...


5

Dynamically selecting the correct API implementation sounds cool, but is actually a nightmare. a REST API exposes a bunch of URIs that identify resources cool URIs don't change here, the interpretation of the URI depends on the implicit version so your URIs do not identify resources by themselves this breaks REST, to some degree Your implicit version ...


1

REST doesn't care what spelling you use for your URIs, beyond the basics that they conform with RFC 3986. The machines don't care after that, in much the same way that the compiler doesn't care what variable names you use. Follow any conventions you like. If your URIs have a hierarchical structure, then you can take advantage of dot segments and relative ...


5

As a rule of thumb with RESTful APIs I've found that you should only ever need to do "one hop" when defining relationships between two entities. As soon as you need to start defining relationships across "two hops" it's normally a sign that the endpoint isn't very RESTful any more. Endpoints should only really be concerned with one entity. Remember this isn'...


1

Almost everything is a balancing act between performance, usability, maintainability. That said... What's the difference between storing session state on the client versus the server? Where the information is stored determines where it is accessible from. If you only store something client-side, the server obviously won't have any knowledge of it. ...


Top 50 recent answers are included