REST vs JSON-RPC? [closed]

The fundamental problem with RPC is coupling. RPC clients become tightly coupled to service implementation in several ways and it becomes very hard to change service implementation without breaking clients: Clients are required to know procedure names; Procedure parameters order, types and count matters. It’s not that easy to change procedure signatures(number of arguments, order … Read more

‘Best’ practice for restful POST response

Returning the new object fits with the REST principle of “Uniform Interface – Manipulation of resources through representations.” The complete object is the representation of the new state of the object that was created. There is a really excellent reference for API design, here: Best Practices for Designing a Pragmatic RESTful API It includes an … Read more

How do I make a request using HTTP basic authentication with PHP curl?

You want this: curl_setopt($ch, CURLOPT_USERPWD, $username . “:” . $password); Zend has a REST client and zend_http_client and I’m sure PEAR has some sort of wrapper. But its easy enough to do on your own. So the entire request might look something like this: $ch = curl_init($host); curl_setopt($ch, CURLOPT_HTTPHEADER, array(‘Content-Type: application/xml’, $additionalHeaders)); curl_setopt($ch, CURLOPT_HEADER, 1); … Read more

How do I upload a file with metadata using a REST web service?

I agree with Greg that a two phase approach is a reasonable solution, however I would do it the other way around. I would do: POST http://server/data/media body: { “Name”: “Test”, “Latitude”: 12.59817, “Longitude”: 52.12873 } To create the metadata entry and return a response like: 201 Created Location: http://server/data/media/21323 { “Name”: “Test”, “Latitude”: 12.59817, … Read more

What’s the difference between “Request Payload” vs “Form Data” as seen in Chrome dev tools Network tab

The Request Payload – or to be more precise: payload body of a HTTP Request is the data normally send by a POST or PUT Request. It’s the part after the headers and the CRLF of a HTTP Request. A request with Content-Type: application/json may look like this: POST /some-path HTTP/1.1 Content-Type: application/json { “foo” … Read more

How to create REST URLs without verbs?

General principles for good URI design: Don’t use query parameters to alter state Don’t use mixed-case paths if you can help it; lowercase is best Don’t use implementation-specific extensions in your URIs (.php, .py, .pl, etc.) Don’t fall into RPC with your URIs Do limit your URI space as much as possible Do keep path … Read more

How to enable CORS in ASP.net Core WebAPI

Because you have a very simple CORS policy (Allow all requests from XXX domain), you don’t need to make it so complicated. Try doing the following first (A very basic implementation of CORS). If you haven’t already, install the CORS nuget package. Install-Package Microsoft.AspNetCore.Cors In the ConfigureServices method of your startup.cs, add the CORS services. … Read more

How do I set a cookie on HttpClient’s HttpRequestMessage

Here’s how you could set a custom cookie value for the request: var baseAddress = new Uri(“http://example.com”); var cookieContainer = new CookieContainer(); using (var handler = new HttpClientHandler() { CookieContainer = cookieContainer }) using (var client = new HttpClient(handler) { BaseAddress = baseAddress }) { var content = new FormUrlEncodedContent(new[] { new KeyValuePair<string, string>(“foo”, “bar”), … Read more

REST API – file (ie images) processing – best practices

OP here (I am answering this question after two years, the post made by Daniel Cerecedo was not bad at a time, but the web services are developing very fast) After three years of full-time software development (with focus also on software architecture, project management and microservice architecture) I definitely choose the second way (but … Read more

Hata!: SQLSTATE[HY000] [1045] Access denied for user 'divattrend_liink'@'localhost' (using password: YES)