Search code examples
node.jsloopbackjs

How to Create a container by using REST url with api?


When referring to the loopback page ,there is an API to create new container,when i am tring to create a container using that URL, all it is showing is

{"error":{"statusCode":404,"name":"Error","message":"There is no method to handle POST /Pictures%20%20?%20{%20%22name%22%20:%20Bhanu%20}","stack":"Error: There is no method to handle POST /Pictures%20%20?
create ()
  {
    var data = { "name" :  this.getUserId()  }
    return new Promise((resolve,reject)=> {
      this.http.post(this.apiUrl+'/Pictures'+ data,{
        headers : new HttpHeaders().set('Content-type','application/json')
      }).subscribe(res => {
        resolve(res);
      },(err) => {
        reject(err);
      });
    });
  }

the expected result should be

{"name":"Bhanu2","size":4096,"atime":"2019-07-01T10:20:39.525Z","mtime":"2019-07-01T10:20:39.525Z","ctime":"2019-07-01T10:20:39.525Z"}

Solution

  • If you want to do a POST request, You cannot just add the request body to the url. Or maybe it is a typo. The + before the data will be comma ,.

    this.http.post(this.apiUrl+'/Pictures',data,{
        headers : new HttpHeaders().set('Content-type','application/json')
    })