Defining route in config.js for Get


#1

Hey guys, I’m fairly new to using Ember CLI, and was wondering how I should go about defining a route in config.js for my HTTPget request.

My controller has a method which gets a list of objects from a web api…

getList: function() { jQuery.ajax({ type: “GET”, url: “url”, data: “parameters”, dataType: “json”, contentType: “application/json; charset=utf-8”, success: function(response) { var objList = .parseJSON(response.d); }, failure: function(msg) { (’#output’).text(msg); } });

How would I go about creating the route for this in config.js?


#2

Instead of “defining a route”, do you really mean, “How can I access a url property defined in config/environment.js”? If so, it’s as simple as:

import ENV from “…/config/environment”;

// …

getList: function() { jQuery.ajax({ type: “GET”, url: ENV.myAPIEndpoint, …


#3

Hey thanks for the reply, but I figured it out.


#4

Great. But please not that it’s considered good practice to explain how you solved your problem, even (or perhaps especially) if the original question is confusing. This forum comes up often for Ember searches.


#5

Hey, sorry about. For the time being, I’m just using temporary data from a fixture. Your suggestion also works.