What's the AngularJS “way” of handling a CRUD resource

前端 未结 5 933
半阙折子戏
半阙折子戏 2021-01-30 03:38

I am interested in moving a lot of my client\'s \"logic\" away from Rails routing to AngularJS. I have slight confusion in one topic and that is linking. Now, I do understand th

5条回答
  •  栀梦
    栀梦 (楼主)
    2021-01-30 03:58

    The angular way is the restful way:

    GET all http://example.com/athletes
    GET one http://example.com/athletes/1
    POST new http://example.com/athletes
    PUT edit http://example.com/athletes/1
    DELETE remove http://example.com/athletes/1
    

    Note that $resource also expects a few other things, like resource URLs not ending with a slash, PUT requests returning the updated resource, etc.

    If your API doesn't meet these criteria, or you simply need more flexibility, you can build your own $resource-like CRUD service based on the lower-level $http service. One way of doing the latter is explained here

提交回复
热议问题