RESTful Soft Delete

You should use DELETE. What you intend to do with your data is called “soft deleting”: you set a flag and avoid flagged items from appearing. This is internal to your webapp and the user doesn’t have to know that you’re soft deleting instead of deleting or whatever you want to do. This is why … Read more

Django Test Client Method Override Header

You need to specify header as ‘HTTP_X_HTTP_METHOD_OVERRIDE’ instead of ‘X_HTTP_METHOD_OVERRIDE’ i.e. add HTTP_ at the beginning of the header. header = {‘HTTP_X_HTTP_METHOD_OVERRIDE’: ‘PUT’} response = client.post(‘/model/1/’, content_type=”application/json”, data=post_data_clean, **header) From the Django documentation: HTTP headers in the request are converted to META keys by converting all characters to uppercase, replacing any hyphens with underscores and … Read more

How to specify python requests http put body?

Quoting from the docs data – (optional) Dictionary or bytes to send in the body of the Request. So this should work (not tested): filepath=”yourfilename.txt” with open(filepath) as fh: mydata = fh.read() response = requests.put(‘https://api.elasticemail.com/attachments/upload’, data=mydata, auth=(‘omer’, ‘b01ad0ce’), headers={‘content-type’:’text/plain’}, params={‘file’: filepath} )

PUT vs. POST for Uploading Files – RESTful API to be Built Using Zend Framework

There seems to be quite a bit of misunderstanding here. PUT versus POST is not really about replace versus create, but rather about idempotency and resource naming. PUT is an idempotent operation. With it, you give the name of a resource and an entity to place as that resource’s content (possibly with server-generated additions). Crucially, … Read more

Curl and PHP – how can I pass a json through curl by PUT,POST,GET

PUT $data = array(‘username’=>’dog’,’password’=>’tall’); $data_json = json_encode($data); $ch = curl_init(); curl_setopt($ch, CURLOPT_URL, $url); curl_setopt($ch, CURLOPT_HTTPHEADER, array(‘Content-Type: application/json’,’Content-Length: ‘ . strlen($data_json))); curl_setopt($ch, CURLOPT_CUSTOMREQUEST, ‘PUT’); curl_setopt($ch, CURLOPT_POSTFIELDS,$data_json); curl_setopt($ch, CURLOPT_RETURNTRANSFER, true); $response = curl_exec($ch); curl_close($ch); POST $ch = curl_init(); curl_setopt($ch, CURLOPT_URL, $url); curl_setopt($ch, CURLOPT_HTTPHEADER, array(‘Content-Type: application/json’)); curl_setopt($ch, CURLOPT_POST, 1); curl_setopt($ch, CURLOPT_POSTFIELDS,$data_json); curl_setopt($ch, CURLOPT_RETURNTRANSFER, true); $response = curl_exec($ch); curl_close($ch); … Read more

How do you do an HTTP Put?

Here’s a C# example using HttpWebRequest: using System; using System.IO; using System.Net; class Test { static void Main() { string xml = “<xml>…</xml>”; byte[] arr = System.Text.Encoding.UTF8.GetBytes(xml); HttpWebRequest request = (HttpWebRequest)HttpWebRequest.Create(“http://localhost/”); request.Method = “PUT”; request.ContentType = “text/xml”; request.ContentLength = arr.Length; Stream dataStream = request.GetRequestStream(); dataStream.Write(arr, 0, arr.Length); dataStream.Close(); HttpWebResponse response = (HttpWebResponse)request.GetResponse(); string returnString = … Read more

Java map.get(key) – automatically do put(key) and return if key doesn’t exist?

The java.util.concurrent.ConcurrentMap and from Java 8 Java.util.Map has putIfAbsent(K key, V value) which returns the existing value, and if that is null inserts given value. So if no value exists for key returns null and inserts the given value, otherwise returns existing value If you need lazy evaluation of the value there is computeIfAbsent(K key, … Read more

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