Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 9126877
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 17, 20262026-06-17T07:09:13+00:00 2026-06-17T07:09:13+00:00

I have defined myself an api for use with Angular.js: angular.module(‘api’, [‘ngResource’]) .factory(‘Server’, function

  • 0

I have defined myself an api for use with Angular.js:

angular.module('api', ['ngResource'])
    .factory('Server', function ($resource) {
        return $resource('http://localhost\\:3000/api/servers/:name');
    })
    .factory('ActiveServer', function ($resource) {
        return $resource('http://localhost\\:3000/api/servers/active/:name', {},
            { start: {method: 'POST'}, stop: {method: 'DELETE'} });
    });

The idea, is that I have a set of defined servers, available through the /api/servers/ uri. A particular server can be started by adding it to the /api/servers/active/ uri, and stopped by deleting it.

In my controller, I have the following code:

$scope.start = function() {
    ActiveServer.start(this.server);
};

$scope.stop = function() {
    ActiveServer.stop(this.server);
};

which again is triggered by buttons

    <div class="well span4" ng-repeat="server in servers">
        <h1>{{server.definition.name}}</h1>
        <span class="label label-info">{{server.status}}</span>
        <button type="button" class="btn btn-primary"
                ng-click="start()">Start</button>
        <button type="button" class="btn btn-primary"
                ng-click="stop()">Stop</button>
    </div>

Starting the server works alright, but I have trouble stopping it. The code above ends up with the following request:

Request URL:http://localhost:3000/api/servers/active?$$hashKey=005&_events=[object+Object]&definition=[object+Object]&status=ready
Request Method:DELETE

The definition-part of my server object, containing the name that identifies the server to stop, isn´t serialized right.

How can I fix this?

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-17T07:09:15+00:00Added an answer on June 17, 2026 at 7:09 am

    If your API (ActiveServer) only needs to receive the server’s name to work, then pass only the server’s name during the service call. Like this:

    $scope.start = function() {
        ActiveServer.start({name: this.server.definition.name});
    };
    
    $scope.stop = function() {
        ActiveServer.stop({name: this.server.definition.name});
    };
    

    Passing the entire this.server object in any service call will result on the entire object being parametrized into the HTTP request.

    extended explanation:

    When you use something like api/servers/:name on your $resource URL, you are basically saying that the :name part will be replaced by the value of a property with the same name (in this case, ‘name’) received on the parameters (i.e. {name: 'someName'}).

    From the angularJS $resource documentation:

    Each key value in the parameter object is first bound to url template
    if present and then any excess keys are appended to the url search
    query after the ?. Given a template /path/:verb and parameter
    {verb:’greet’, salutation:’Hello’} results in URL
    /path/greet?salutation=Hello. If the parameter value is prefixed with
    @ then the value of that parameter is extracted from the data object
    (useful for non-GET operations).

    So, if you call service.get({name: 'abc'}) then URL of the request will be
    api/server/abc

    If you call service.get({name: 'abc', id: '123'}) then URL will be api/server/abc?id=123

    In your case, the this.server Object looks something like this:

    { 
      $$hashKey: 005,
      _events: {},
      definition: {},
      status: ready
    }
    

    Since AngularJS does not do in-depth parametrization, _events and definitions are shown as _events=[object+Object]&definition=[object+Object] on the URL.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have defined the following two functions test <- function(t) { return( (0.5*eta^2/theta)*(1-exp(-2*theta*t)) )
in my self-defined module I have this method which will query the db and
I have defined the following class using COM to use the IGroupPolicyObject using C#.NET:
I have defined CSS in MasterPage so that all pages can use the same
i've started to introduce myself into REST. I use as REST-framework Restlet. I have
I use Hibernate and mySql. I have defined the db script as follows: CREATE
I have linkers errors(undefined reference) that I cannot solve by myself. I use GCC
I have defined following control template for my custom control. <ControlTemplate TargetType={x:Type local:CustomControl}> <Grid
I have defined a ConfigurationProperty class, which is basicly a key-value pair (with key
I have defined a table type PL/SQL variable and added some data there. create

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.