2014年04月

RESTful URL for adding record to a record

What's the correct "RESTful" URL for an action that adds a child record to a parent record?



For example, if I wanted to provide a URL for adding a "comment" record to an "order" record, how should I format it?



My first thought was something like:



PUT http://example.com/order/12345/comment/add


I work in Django, which uses a similar pattern, so this seemed most intuitive. However, reading over some RESTful design guides like this one suggests that this might be bad practice, as they argue the "PUT" and "add" are redundant and therefore might create confusion.



Answers

I would do the following:



POST http://example.com/order/12345/comment


Answers

The put action and the add part of the url are redundant. But there is no hard rule on any of this. I see apis having that form, even from major vendors, and sometimes simply remark "The put action and the uri segment are redundant" Sometimes I say nothing at all and just call the endpoint. If I were writing an api, I would probably leave off the add part.



Answers

there are few points to make your request RESTful:



1) Use resources names in the URL in plural and not in a singular form (orders instead of order)



2) never use ACTION names in your URL such as (ADD) in "comment/add"



3) since you are adding a "NEW" comment without knowing any IDs of hands you should use POST request.



Finally, the URL I would recommend is:



HttpVerbs = POST
http://api.example.com/orders/12345/comments



That should add a new comment to your order#12345



Answers

There is no one-size-fits-all answer to your question. Rest URLs can be whatever you want them to be. At the end of the day, they are routes that get mapped to a method. I wouldn't worry too much about the "best" URL. I prefer to find a standard that works for me and then move on to bigger, more important things. As long as clients know what the URL is, they will be fine.





Question

I want to file a Lis Pendends in fl to quiet title by person claiming title by adverse possession hold long do you need to wait to file



Answer

The lis pendens should be filed immediately upon filing the lawsuit. It puts the world on notice of the pending action and prevents transfer of the property without knowledge by the person receiving title. If you are the record title owner of the property you may not want to file the lis pendens. consult with an attorney.





Can't get visibility of JSON in php when receiving POST data from Parse beforeSave webhook

I am trying to create a beforeSave Parse webhook but am struggling to get visibility of the JSON passed to the webhook URL.



The process I am following is:



In Swift iOS call the following function to post to Parse



func createNewHouseMate(){

var housemate = PFObject(className: "HouseMates")

housemate["email"] = "bobbyball@hotmail.com"

housemate["houseName"] = "Matchstick House"

housemate["housemateNumber"] = 3

housemate["firstName"] = "Bobby"

housemate["lastName"] = "Ball"

housemate["dob"] = "14/08/1996"

housemate["nationality"] = "GB"

housemate["countryOfResidence"] = "GB"

housemate.saveInBackgroundWithBlock { (succeeded:Bool, error:NSError?) -> Void in

}

}


In Parse I have set up a webhook with the following parameters:



Webhook Type:  beforeSave
Class: HouseMates
URL: https://samplepaymentsandbox.com/Sandbox/webhookTest.php


The server side is on Azure and the code for the php page is:



<?php

// now try to pass the supplied information back

// i think success is either {"success" : true}

// or {"success" : object}

// or {"error" : "string saying what the error was"}

// maybe email it

require '../demo/PHPMailer/PHPMailerAutoload.php';

$mail = new PHPMailer;

$mail->isSMTP(); // Set mailer to use SMTP

$mail->Host = 'smtp.sendgrid.net'; // Specify main/backup SMTP servers

$mail->SMTPAuth = true; // Enable SMTP authentication

$mail->Username = 'azure_1877598753873209752305230@azure.com'; // SMTP username

$mail->Password = ‘3ufuhi3u5iu3nj'; // SMTP password

$mail->SMTPSecure = 'tls'; // Enable TLS/SSL encryption

$mail->Port = 587; // TCP port to connect to


$mail->From = 'payments@ samplepaymentsandbox.com';

$mail->FromName = ’SampleName';

$mail->addAddress(‘XYZr@hotmail.com’,'XYZ'); // Add a recipient

$mail->WordWrap = 50; // Set word wrap to 50 characters

$mail->isHTML(true); // Set email format to HTML


$mail->Subject = 'Webhook POST data';

$i = 0;


$testvar = json_decode($_POST);

$bodyText = "<p>$testvar</p>";

$mail->Body = $bodyText;





if(!$mail->send()) {

echo 'Message could not be sent.';

echo 'Mailer Error: ' . $mail->ErrorInfo;

} else {

// echo 'Message has been sent’;

$i=1;


}



$data2 = array( 'error' => "Error thrown for testing");

return json_encode( $data2 );


?>




Format method failure

If I put this string as input to method format:
"07/11/2009 00:33:22" with format: "yyyy/mm/dd hh:mm:ss" then as a result I get:
2009-07-11 00:33:22.



Why month is swapped with day? How to fix it?



Answers

Actually month and day are not swapped in your output, but it's the formatting of your input what is misleading. Try =month("07/11/2009 00:33:22") in a cell to see what is really month and day in your original data.



If your input is from a range, stored as data, then it's really 11th of July.



If your input is a string from any source, then look for the regional settings of your pc (control panel) to change default settings.



Update

To ensure your text is converted to date the same way regardless your regional settings use this formula:

=date(mid(A1,7,4),mid(A1,4,2),mid(A1,1,2)) + time(mid(A1,12,2),mid(A1,15,2),mid(A1,18,2))



Answers

Assuming you are inputting the 7th of November 2009:



Format: "yyyy/dd/mm hh:mm:ss"


This will give you 2009/07/11 etc.



EDIT: Since someone is downvoting without any explanation, and since OP now seems to have decided on the order of input:



Assuming input 11th of July 2009:



Format: "yyyy/mm/dd hh:mm:ss"


This will give you 2009/07/11 etc.



Setting custom formatting to a cell, a selection of cells or an entire row or column will override regional settings. If this doesn't work, it's probably because the formatting isn't being forced to update.



Once you've applied the formatting, select the affected range or rows/columns, go to the Data tab, and click "Text To Columns". Unselect any optional checkboxes and follow the rest of the wizard. The formatting will now update across all selected cells.





Copy elements from vector based on condition C++

I'm using C++ to create Hopcroft's algorithm for DFA Minimization.



Part of Hopcroft's algorithm is to - initially - divide two sets (P with accept and non-accept states and Q with non-accept states only). I already have group P, and from P I'm trying to extract Q. I'm using the following code to do it:



for(int i=0; i<groupP.size(); i++)
if(groupP[i]->final)
groupQ.push_back(groupP[i]);


in which groupP and groupQ are:



vector<node*> groupQ;
vector<node*> groupP;


and node is a structure that I've created to represent a node of my automata. It's guaranteed that the boolean attribute "final" is already correctly set (false for non-final states, true for final states).



Finally, my question is: is it correct to copy one element from a vector to another by doing what I've done? If I modify the content of a copied element from groupP, will this same element be modified in groupQ as well?



Answers

Right now, you have vectors of pointers. When you copy from one vector to another, you're copying the pointers, not the elements themselves.



Since you have two pointers referring to the same node, any modification made to a node will be visible in the other group--i.e., if yo make a change to groupP[i]->foo, then the same change will be visible in groupQ[j]->foo (provided that groupP[i] is one of the elements you copied from groupP to groupQ.



If you don't want that, you have a couple of choices. One would be to leave groupP and groupQ in the same vector, but partition the vector based on the state of an element's final member:



auto P_end = std::partition(groupP.begin(), groupQ.end(), 
[](node *n) { return n->final;});


Then [groupP.begin(), P_begin) is groupP (i.e., final==true) and [P_begin, groupP.end()) is groupQ (i.e., final==false).



This moves the pointers around (and gives you an iterator so you know the dividing line between the two) so you have exactly one pointer to each element, but they're separated into the two relevant groups.



As a final possibility, you might want to actually copy elements from groupP to groupQ, and in the process create a new element, so after you copy items from groupP to groupQ, each item you copied now exists in two place--i.e., there's one element in groupP and one element in groupQ. Either one can be modified, but they're separate from each other, so either can be modified, but a modification to one has no effect on the other.



The most obvious way to achieve that would be be to just use vectors of nodes:



vector<node> groupQ;
vector<node> groupP;


This way, when you copy from one group to the other, you're copying the nodes themselves rather than pointers to nodes, so each copy creates a new, independent node with the same value as an existing node.



Answers

You could use std::copy_if which does the same thing:



std::copy_if(groupP.cbegin(), groupP.cend(),
std::back_inserter(groupQ),
[](node* n){ return n->final; });


Since you are manipulating pointers, the elements themselves are shared, so modifying a node in one of the container can be seen from the other.



Note that manipulating raw pointers like you are doing is very error prone, and you may want to use shared pointers for instance.



Edit: Adding missing std::back_inserter.





↑このページのトップヘ