get

HTTP Get with 204 No Content: Is that normal

▼魔方 西西 提交于 2019-12-03 05:30:42
问题 Is it a normal occurrence for an HTTP GET Request to have a response with status code 204 - No Content ? Like, is this semantically correct with respect to what an HTTP GET is supposed to accomplish? I know that a 204 - No Content is okay for an HTTP POST Request . For GET request, if no data is to be sent back, is the 204 status code appropriate? Should I use 404, or just stick to 200 for success but have an empty response? The use case for this question is a Java application that I am

ElasticSearch POST with json search body vs GET with json in url

杀马特。学长 韩版系。学妹 提交于 2019-12-03 05:26:51
According to the ES documentation, those 2 search request should get the same results: GET http://localhost:9200/app/users/_search?source={"query": {"term": {"email":"foo@gmail.com"}}} POST http://localhost:9200/app/users/_search Post body : { "query": { "term": { "email":"foo@gmail.com" } } } But the first one gives no result while the second one gives me the expected result. I use ES version 0.19.10 Did anybody else have the same behavior ? Is this a bug ? Andrew Macheret source is not a valid query string argument according to URI Search Elasticsearch allows three ways to perform a search

Set headers on get request angular 2

不打扰是莪最后的温柔 提交于 2019-12-03 05:14:46
I try to set an Authorization header to a GET request to authenticate users to a rest API. I'm using Angular 2 RC1. (I'am a total beginner). getTest(){ let authToken = localStorage.getItem('auth_token'); let headers = new Headers({ 'Content-Type': 'application/json' }); headers.append('Authorization', `Bearer ${authToken}`); let options = new RequestOptions({ headers: headers }); return this._http .get(this._url,options) .map(res => console.log(res)); } I allow CORS in my backend. header("Access-Control-Allow-Origin: *"); header("Access-Control-Request-Headers: Content-Type, Authorization");

What headers do I want to send together with a 304 response?

旧巷老猫 提交于 2019-12-03 05:10:34
When I send a 304 response. How will the browser interpret other headers which I send together with the 304? E.g. header("HTTP/1.1 304 Not Modified"); header("Expires: " . gmdate("D, d M Y H:i:s", time() + $offset) . " GMT"); Will this make sure the browser will not send another conditional GET request (nor any request) until $offset time has "run out"? Also, what about other headers? Should I send headers like this together with the 304: header('Content-Type: text/html'); Do I have to send: header("Last-Modified:" . $modified); header('Etag: ' . $etag); To make sure the browser sends a

Using getter/setter vs “tell, don't ask”?

大憨熊 提交于 2019-12-03 04:20:12
Tell, don't ask principle here is often pasted to me when I use getters or setters, and people tell me not to use them. The site clearly explains what I should and what I shouldn't do, but it doesn't really explain WHY I should tell, instead of asking. I find using getters and setters much more efficient, and I can do more with them. Imagine a class Warrior with attributes health and armor : class Warrior { unsigned int m_health; unsigned int m_armor; }; Now someone attacks my warrior with a special attack that reduces his armor for 5 seconds. Using setter's it would be like this: void

How can I get access to a Django Model field verbose name dynamically?

感情迁移 提交于 2019-12-03 04:18:54
I'd like to have access to one my model field verbose_name. I can get it by the field indice like this model._meta._fields()[2].verbose_name but I need to get it dynamically. Ideally it would be something like this model._meta._fields()['location_x'].verbose_name I've looked at a few things but I just can't find it. Ignacio Vazquez-Abrams For Django < 1.10: model._meta.get_field_by_name('location_x')[0].verbose_name model._meta.get_field('location_x').verbose_name For Django 1.11 and 2.0: MyModel._meta.get_field('my_field_name').verbose_name More info in the Django doc The selected answer

Check if request is GET or POST

时间秒杀一切 提交于 2019-12-03 04:16:13
In my controller/action: if(!empty($_POST)) { if(Auth::attempt(Input::get('data'))) { return Redirect::intended(); } else { Session::flash('error_message',''); } } Is there a method in Laravel to check if the request is POST or GET ? Of course there is a method to find out the type of the request, But instead you should define a route that handles POST requests, thus you don't need a conditional statement. routes.php Route::post('url', YourController@yourPostMethod); inside you controller/action if(Auth::attempt(Input::get('data'))) { return Redirect::intended(); } //You don't need else since

JavaScript get/set methods vs. standard methods

霸气de小男生 提交于 2019-12-03 03:53:22
Why does JavaScript have two different ways to get/set object properties? Example: //implementation 1 var obj1 = { "x":1, get number() {return this.x}, set number(n) {this.x = n} } //implementation 2 var obj2 = { "x":1, getX: function(){return this.x}, setX: function(n){this.x = n} } Does one implementation style have advantages over the other? Unlike normal methods, using get and set lets you operate on the object's properties directly (=== cleaner/lesser code) - while actually invoking the getter and setter methods behind-the-scenes. var obj1 = { "x":1, get number() {console.log('get was

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

谁说我不能喝 提交于 2019-12-03 03:25:42
问题 I am sick of the following pattern: value = map.get(key); if (value == null) { value = new Object(); map.put(key, value); } This example only scratches the surface of the extra code to be written when you have nested maps to represent a multi-dimensional structure. I'm sure something somewhere exists to avoid this, but my Googling efforts yielded nothing relevant. Any suggestions? 回答1: The java.util.concurrent.ConcurrentMap and from Java 8 Java.util.Map has putIfAbsent(K key, V value) which

REST GET verb with parameters

跟風遠走 提交于 2019-12-03 02:48:54
I'm sitting reading on some REST with my fellow teammates, we are writing a RoR application that is going to expose some of its functionality to the rest of the world. My task on this team is to make a ressource that exposes journal reports. If you call http://root.com/journalreports You should get all the journalreports from the service. Thats working like a charm, but I'm confused on how to properly make a ressource that exposes a range of journalreports. Should I make it http://root.com/journalreports?range=1/2/2010;5/2/2010 Or is this illegal when we talk about REST because of the ?range=