Query string http param in play framework 1.2.5 - playframework-1.x

i need to add a route for following syntax
/bidding/12345?access_token=ACCESS_TOKEN
in my routes file i add like this
GET /bidding/{id} Application.bidding
i try to send request with query param /bidding/12345?access_token=ACCESS_TOKEN like above but play response is 404 (not found), i was using play framework 1.2.5
thanks for any response to my question, and sorry for my bad English

The URL you are trying to access is not represented correctly in the routes file.
If you would like to access the URL:
/bidding/12345?access_token=ACCESS_TOKEN
The routes file entry will need to be changed to the following:
GET /bidding Application.bidding
Play will use its magic to route that GET request to the following method in the Application controller:
public static void bidding(String access_token)

Your route configuration seems ok : are you sure you have a valid public static method bidding in your Application class ? Could you post the source of this method ?

Related

How to request with request header to https URL using C++ REST SDK?

I'm trying to make source that requests to specific https URL with request header using c++ rest sdk.
ex)https://111.0.0.1:1111/vl/api/auth
Then, I want to allocate response value to char* value and print.
It is first time to use rest sdk. So I searched many things.
But,there are no solutions request 'Get' with request header
RequestHeader is like this :
id:"1234567890"
auth:"7d8ffbecb05d59459f96d6e3aac8542e"
But I don't know what to do
httpclient client(U("http://localhost:9991/test"));
////then How???
I need your help!
all you need to do like
http_request request(methods::GET);
request.headers().add(L"id", L"1234567890");
request.headers().add(L"auth", L"7d8ffbecb05d59459f96d6e3aac8542e");

ckan.toolkit.redirect_to does not redirect

I'm currently developing an ckan extension, where i need to redirect to a url on a different domain.
In my plugin i defined a custom action function:
#side_effect_free
def download_json(context, data_dict):
toolkit.redirect_to('http://my.json-builder.com?id=1234')
But when i call this endpoint i just get following response:
response screenshot
So i assume that the action function is called, but the redirect_to call does not redirect to the url i defined.
Thanks for your help!
Florian
It's a bit hard to figure out what you're trying to accomplish but here's a few things I hope will help.
Short Answer:
No, you can't redirect from an API endpoint in CKAN. The endpoint response in CKAN is built up and expects certain things from your action. Your action should return some kind of result. In your case it's returning nothing but trying to redirect. A logic action function with IActions is not the same as a Blueprint or pylons controller action.
See Making an API request docs, specifically the breakdown of an API response in CKAN. Also, you can review the pylons implementation that builds up the API response or the flask blueprints implementation.
More Info to help with your approach:
You say you are trying to call an endpoint that redirects a user to a different domain url. Based on this consider the following:
The first thing I thought you wanted was to have a url that someone goes to through the web interface of your site and are redirected to another site. In this case your example code of toolkit.redirect_to('http://my.json-builder.com?id=1234') makes sense and works for a custom controller action using/implemented with IRoutes or if you're using flask then IBlueprint. A User would go to a URL on your site such as http://localhost.com/download_json and be redirected to the new URL/site in their browser.
If you are intending this to be an API call for other users this starts to feel a little bit odd. If a user is using your API, they would expect to get results from your site in JSON CKAN's API is designed to return JSON. Someone consuming your API endpoint would not expect to be redirected to another site e.g. if I called http://localhost.com/api/3/action/download_json I would expect to get a JSON object like
{
help: "http://localhost/api/3/action/help_show?name=download_json",
success: true,
result: {
...
}
}
They would look for success to make sure the call worked and then they would use the result to keep moving forward with their desired processes. If you do want someone via an API to get redirect info I'd likely return the redirect url as the result e.g. result: {'redirect_url': 'http://my.json-builder.com?id=1234'} and document this well in your extension's API docs (e.g. why you're returning this endpoint, what you expect someone to do with it, etc).
If this is an API call for your own extension I'm guessing what you are trying to do is use my.json-builder.com to build a json of something (a dataset maybe?) and return that json as the result at your endpoint or maybe even consume the result to make something else? If that's the case, then in your function you could make the call to my.json-builder.com, process the results and return the results to the user. In this case, you're not actually wanting to redirect a user to a new site but instead make a call to the new site to get some results. If you actually want the results for your extension you don't need an additional endpoint. You could make the call from your extension, consume the results and return the desired object you're trying to create.
Hope this helps and sorry if I've miss-understood completely.

How to pass through `ember-cli-mirage` request to a specific API and Host

I am trying to use passthrough feature of ember-cli-mirage to allow my app to request to different API and Host.
export default function() {
//window.server = this;
//this.namespace = 'api';
this.passthrough('locales/en/translation.json');
this.get('/api/customers');
this.passthrough();
this.host='https://abcd.site.com';//need something like this, but not working
this.namespace = 'api/Service.svc';
};
I want to point the requests to outside of the environment where current ember server is running.
But the requests which are passing through fixed URL's like /api/authenticate.
It is throwing exceptions as follows.
POST http://localhost:4200/api/authenticate 404 (Not Found)
I want configure the requests to something like this below
https://abcd.site.com/api/Service.svc/authenticate
Is there any option available in ember-cli-mirage/ pretender? Please help.
Passthrough is correct. Just give the full url as parameter, like:
this.passthrough('https://abcd.site.com/api/Service.svc/authenticate');
Take a look at the twitter example here: http://www.ember-cli-mirage.com/docs/v0.2.x/route-handlers/

EmberJs as a PhoneGap with external API

please can you advise on the following:
I have a web application written in emberjs with Rails as back-end. And now I'm going to port this application with phonegap to iOS, and the thing that I'm struggling is how to set my API endpoint that will be working in iPhone?
As I understand EmberJs when used on the web via browser, uses your current location to issue API requests, but this approach doesn't working when using the application as iOS app.
I'm really looking for some elegant solution to simply replace the host name or something?
Thanks for help!
UPDATE:
This one works for changing the API URL
DS.RESTAdapter.reopen({
url: 'http://somedomain.com'
});
But now, there is access-controll issue:
Origin http://somedomain.com is not allowed by Access-Control-Allow-Origin.
Since you haven't posted any code on how your adapter is configured, this is the right way to set a custom url for your adapter:
DS.RESTAdapter.reopen({
url: 'https://somedomain.com/api'
});
Then if you have a model e.g. App.User, the requests for the list of App.User would now go to https://somedomain.com/api/user/ and for a specific user id to https://somedomain.com/api/user/123 respectively.
Update
When testing from the browser you have to start the browser (assuming chrome) with the flag --disable-web-security to make cross origin work. But in real live you have to configure your server to set the response HTTP HEADERS using:
Access-Control-Allow-Origin: *
Access-Control-Allow-Methods: GET, POST, ...
So in the case of rails you could do something like this to configure your controllers serverside to accept cross origin requests and set the headers accordingly:
...
after_filter :cors_set_access_control_headers
def cors_set_access_control_headers
headers['Access-Control-Allow-Origin'] = '*'
headers['Access-Control-Allow-Methods'] = 'POST, GET, PUT' # etc. etc.
headers['Access-Control-Max-Age'] = "1728000"
end
...
For more extensive examples on how to configure CORS for rails you could search for "CORS for JSON and Rails" for example.
Hope it helps

The Request URL is being called twice when using URLRewrite Filter

I am using Tuckey URL Rewrite filter. I have installed it on my Google App Engine (Java). and it is working well besides one annoying thing. Apparently when the request URL is re-written and handled by the controller a new request is being issued with no parameters to the same controller. This happens after the HTTP response has been returned from the first call.
I have copied the basic configuration I read on the site and did not change it much.
What could have gone wrong?
It seems that Tuckey URL Rewrite filter is working properly.
I had an issue with jQuery UI Tabs which issue the request twice.