Angular JS: Full example of GET/POST/DELETE/PUT client for a REST/CRUD backend?

后端 未结 3 1250
失恋的感觉
失恋的感觉 2020-12-04 06:02

I\'ve implemented a REST/CRUD backend by following this article as an example: http://coenraets.org/blog/2012/10/creating-a-rest-api-using-node-js-express-and-mongodb/ . I h

3条回答
  •  不思量自难忘°
    2020-12-04 06:03

    You can implement this way

    $resource('http://localhost\\:3000/realmen/:entryId', {entryId: '@entryId'}, {
            UPDATE: {method: 'PUT', url: 'http://localhost\\:3000/realmen/:entryId' },
            ACTION: {method: 'PUT', url: 'http://localhost\\:3000/realmen/:entryId/action' }
        })
    
    RealMen.query() //GET  /realmen/
    RealMen.save({entryId: 1},{post data}) // POST /realmen/1
    RealMen.delete({entryId: 1}) //DELETE /realmen/1
    
    //any optional method
    RealMen.UPDATE({entryId:1}, {post data}) // PUT /realmen/1
    
    //query string
    RealMen.query({name:'john'}) //GET /realmen?name=john
    

    Documentation: https://docs.angularjs.org/api/ngResource/service/$resource

    Hope it helps

提交回复
热议问题