javascript - Angular JS - Express Routing -
i running mean framework express routing requests. have 2 main routes public/
, app
.
with app being api , public being set of web pages reads data api.
// setting app router , static folder app.use(express.static(path.resolve('./public')));
i have 2 controllers in public folder, home , header.
in home controller using angular js call api , return results.
the api allows filtering through use of query strings:
$http.get('http://search?sumboth=1&customer=' + customer)
i build route specific controller along lines of
http://url/customers/customername
where customername
set customer variable
question
a) best done in angular or express? b) , how implement such routing?
i hope question received, please comment, if need more information.
i understand response of $http.get('http://host/path?sumboth=1&customer=' + customer)
list of search results. in case path should collection path, it's not best practice have search terms in path. subcollection paths pretty standard (something http://host/customers/search?params
, still specific search terms should go in query string)
if on contrary expect retrieve 1 result identificator (provided instance customer name unique) that's different story, should use http://host/customers/:identifier
.
in case can use angular resources, both parts of application need aware of routing. in front-end define additional verb adds filters (or use standard query
1 - see https://docs.angularjs.org/api/ngresource/service/$resource). in back-end need route call , parse parameters. if it's list, parse query string , render result array, if it's single resource, parse identifier, find corresponding resource , render back.
Comments
Post a Comment