Extjs application with Json-server not working fine - json

I have a small app and I am using Rest Proxy. I set up json-server https://github.com/typicode/json-server locally.
I have not changed anything in server settings. I am able to successfully GET data from server but when I try to create data like this
var people = App.model.myModel;
var ed = new people({"id": 2,"title": "test","body": "test"});
ed.save();
Error appears in browser console is
PUT http://localhost:3000/posts/11?_dc=1427464731634 404 (Not Found)
Can some one point out why it is trying to PUT data and not POST data ?

PUT is used to update an item, Not Create.
As you have specified an id value ExtJs will presume that you need to update the record rather than create it, therefore making the PUT request.
Most RESTful API's will provide GET, PUT, POST and sometimes DELETE, LINK Endpoints for each entity.

I found the problem my self. I was sending the "id" as well and it was looking for a post with Id 2, and obviously that doesn't exist.
var people = App.model.myModel;
var ed = new people({"title": "test","body": "test"});
ed.save();
Works perfectly

Related

How to declare multiple Un-authorized URL's in apache Shiro configuration

I am trying out the Apache Shiro framework and I basically downloaded the setup from a project online. I managed to get it working but I am stuck at a really small issue. I want to make multiple JSF pages in my project to be accessed without any authorization.
The configuration currently looks something like:
authc = org.apache.shiro.web.filter.authc.PassThruAuthenticationFilter
authc.loginUrl = /login.xhtml
roles.unauthorizedUrl = /login.xhtml
Now I would like to add one more page to roles.unnauthorizeddUrl i.e. signUp.xhtml
I tried
roles.unauthorizedUrl = /login.xhtml,/signUp.xhtml
but that doesnt work. Is there a way to declare multiple unauthorized URL's in the config.
The roles.unauthorizedUrl is the Url to which the user has to be redirected in case user tried to access the protected / unauthorized url. So you only add one such URL, otherwise ambiguity will be raised to the framework to which url to redirect.
If you want unprotect any url use the below config in [urls] section
/login.xhtml = anon
/sugnUp.xhtml = anon

Web API call not returning

I have a RESTful Web API that is running properly as I can test it with Fiddler. I see calls going through, I see responses coming back.
I am developing a tablet application that needs to use the Web API in order to fetch data or make updates in the repository.
My calls do not return and there is not a single trace in the Fiddler to show that my calls even reach the server.
The first call I need to make is to login. The URI would be this:
http://localhost:53060/api/user
This call would normally return some information about the user (such as group membership, level of authorization and so on). The Web API uses Windows Authentication, so the repository is able to resolve all these fields based on the credentials passed in. As I said, in Fiddler I see the three calls made to the URI as the authentication is negotiated between the caller and the server. The third call returns with a JSON object that contains all information generated from the repository as expected.
Now, moving to my client I have the following:
var webApiClient = new HttpClient(new HttpClientHandler()
{
UseDefaultCredentials = true
})
{
BaseAddress = new Uri("http://localhost:53060/")
};
webApiClient.DefaultRequestHeaders.Accept.Add(new MediaTypeWithQualityHeaderValue("application/json"));
HttpResponseMessage response = await webApiClient.GetAsync("api/user");
var userLoginInfo = await response.Content.ReadAsAsync<UserLoginInformation>();
My call to "GetAsync" never returns and, like I said, I see no trace of it in Fiddler.
Any idea of what I'm doing wrong?
Changing the URL where the Web API was exposed seemed to have fixed the problem. Thanks to #Nkosi for the suggestion.
For anyone stumbling onto this question and asking themselves how to change the URL of the Web API, there are two ways. If the simulator is running on the same machine with the Web API, the change has to be made in the "applicationhost.config" file for IIS Express. You can locate this file by right-clicking on the IIS Express icon in the Notification Area (the bottom right corner) and selecting show all websites. Highlight the desired Web API and it will show where the application host configuration file is located. In there, one needs to locate the following section:
<bindings>
<binding protocol="http" bindingInformation="*:53060:localhost" />
</bindings>
and replace the "localhost" name with the IP address of the machine where the Web API is running.
However, this approach will not work once you start testing your tablet app with a real device. IIS Express must be coerced into exposing the Web API to the outside world. I found an excellent node.js package that can help with that. It is called IISExpress-proxy.

Update record in ServiceNow by passing JSON object in the URL

I am trying to update a record in a ServiceNow instance (running Calgary) using the JSON Web Service, but unfortunately it is not happening.
I am able to insert the record but the update operation doesn't happen.
The call in the Developer tools of chrome (Network section) looks good (could see the url and JSON object bound with data)
Here's the code snippet with the URL I'm testing:
var url = 'https://<instance name>.service-now.com/u_test_employee.do?JSON&sysparm_query=u_number=EMP0001102&‌​sysparm_action=update'
var responsePromise = $http.post(url, dataObj, {});
Any ideas or suggestion is appreciated.
Probable cause for failure of update operation might be missing ACLs. The table which you are trying to update need to have table level write ACL otherwise by default no write (update) operations are allowed

Salesforce REST API and the DELETE method

I'm using Adobe AIR and integrating with the force.com platform via the REST API, and so far it's been relatively smooth sailing, but I'm coming unstuck on using the DELETE method.
The documentation is simple enough:
Deleting an Account Record
Use the DELETE method to delete a record.
In this example, an Account record is deleted.
Example usage for deleting fields in an Account object
curl https://instancename.salesforce.com/services/data/v20.0/sobjects/Account/001D000000INjVe
-H "Authorization: Bearer token" -H "X-PrettyPrint:1" -X DELETE
Example request body for deleting an Account record
none required
Example response body for deleting an Account record
none returned
My code is below, note that the second parameter of HTTPConnection.send() is the method to call.
var headers:Object = new Object();
headers["Authorization"] = "Bearer "+ConnectionAccessToken;
var url:String = ConnectionInstanceURL + "/services/data/v"+_apiVersionNumber+"/sobjects/"+type+"/"+id;
var response:RESTResponse = new RESTResponse(callback);
var httpCallback:IResponder = new mx.rpc.Responder(response.resultHandler,response.faultHandler);
HTTPConnection.send(headers,"DELETE",url,httpCallback);
Similar code works perfectly for other operations, and the weird thing is that this doesn't fail per se, rather it receives a success response, but gets the record in question back with all of it's fields. It would appear that I'm seeing the results of [select * from Object where Id = <id>, and just to clarify the record is not deleted. The object doesn't have any master detail relationships, so I'm not sure what else might be stopping this delete from happening — has anyone run into this before or have suggestions on how to resolve it?
With the setup I am using (where HTTPConnection is a custom class using HTTPService internally), the Adobe documentation states that the only HTTP methods available for me to use are just GET and POST:
"Optionally, you can pass parameters to the specified URL. When you do not go through the server-based proxy service, you can use only HTTP GET or POST methods. However, when you set the useProxy property to true and you use the server-based proxy service, you can also use the HTTP HEAD, OPTIONS, TRACE, and DELETE methods."
This is why the delete was failing as it must have been sending as a GET instead as per jkraybill's comment above. After experimenting I have found that POST can be used, with the actual method to call included as a parameter to the URL:
HTTPConnection.send(headers,"POST",url + "?_HttpMethod=DELETE",httpCallback);

Post an object of type Reference

I have had this problem for some time now and I have seen others have it as well. It has to deal with posting your custom objects that you create in Open Graph to post with your application. I am having this problem primarily on all platforms, but right now let's say I am using Android. If someone has accomplished this in C# or on IOS or even in PHP please post your answer.
An Example:
I have an object that posts a meal to Facebook. Let's say its properties are the following.
mealName = "Lunch"
mealType = "Vegetarian"
mealLocation = "Somewheresville, OH"
Now I have another object in my Open Graph and it is called DailyFood. It has properties such as the following.
day = "12/01/2012"
meal = "MyCustomMeal" // This references a meal object
Now when I go to post that I try to do the following in Java.
//Build Meal
JSONObject mealData = new JSONObject();
mealData.put("mealName", "Lunch");
mealData.put("mealType", "Vegetarian");
mealData.put("mealLocation", "Somewheresville, OH");
Bundle params = new Bundle();
params.putString("day", "12/01/2012");
params.putString("meal", mealData.ToString());
AsyncFacebookRunner request = new AsyncFacebookRunner(facebook);
This is where I generate the following error code.
{"error":
{"message":"(#3503) is an invalid value for property
\"meal\" with type \"Reference\"","type":"OAuthException","code":3503}}
Now I know that it says OAuthException but I am able to post feeds to Facebook with this app just fine. If anyone else has experienced this error on any platform and has found a solution please post it here.
Thanks!
So the answer to this question is that you actually need a website available for your app to be able to reference what its posting to Facebook. In the docs, I at least, wasn't able to find out where this was noted.
according to this official video you must have the web application to post the action using open graph,no matter in which platform we are working android,ios etc
as it fetches the meta tags and properties from the web url only which works as refrence.