Search code examples
angularjsrestangular-resource

REST API Endpoint for Retrieving Empty Object


I have a REST API endpoint for creating an empty object. What is the "standard" url scheme for this GET method? I'm currently using a factory in an angularjs app to make the call to the server.

Right now I have the following scheme:

GET 
Item/new/

My $resource:

 ngServices.factory("TESTfactory", function ($resource) {
                    return $resource("testNewItem/new", {}, {
                            create: {method: 'GET'}
                        }
                }

A successful call to the above resource:

$scope.newItem = TESTfactory.newItem.create();

Any other suggestions would be much appreciated.

I've looked at the following links, which did not specifically list a url scheme for getting empty objects:

  1. REST API Overview
  2. Quick Reference section in this doc

Solution

  • A GET method should never create something. GET is supposed to be nullipotent, which means that it should have no side-effects. Creating a resource is certainly a side effect.

    So, the standard http call would be

    POST 
    Items/create
    

    or

    POST
    Items/new
    

    or better yet just

    POST
    Items/