相关疑难解决方法(0)

使用restful HTTP创建单个和多个资源

在我的API服务器中,我定义了此路由:

POST /categories
Run Code Online (Sandbox Code Playgroud)

要创建一个类别,您可以:

POST /categories {"name": "Books"}
Run Code Online (Sandbox Code Playgroud)

我想如果你想创建多个类别,那么你可以这样做:

POST /categories [{"name": "Books"}, {"name": "Games"}]
Run Code Online (Sandbox Code Playgroud)

我只是想确认这是Restful HTTP API的一个好习惯.

或者应该有一个

POST /bulk
Run Code Online (Sandbox Code Playgroud)

允许他们一次做任何操作(创建,阅读,更新和删除)?

rest web-services http web

17
推荐指数
3
解决办法
2万
查看次数

Restlet用json接收和响应实现帖子

首先,我想知道的是我正在做的是正确的方法.

我有一个场景,我将收到一个json请求,我必须更新数据库,一旦数据库更新,我必须回复json确认.

到目前为止我所做的是创建类扩展应用程序如下:

     @Override  
     public Restlet createRoot() {  
         // Create a router Restlet that routes each call to a  
         // new instance of ScanRequestResource.  
         Router router = new Router(getContext());  

         // Defines only one route  
         router.attach("/request", RequestResource.class);  

         return router;  
     }  
Run Code Online (Sandbox Code Playgroud)

我的资源类是扩展ServerResource,我的资源类中有以下方法

@Post("json")
public Representation post() throws ResourceException {
    try {
        Representation entity = getRequestEntity();
        JsonRepresentation represent = new JsonRepresentation(entity);
        JSONObject jsonobject = represent.toJsonObject();
        JSONObject json  = jsonobject.getJSONObject("request");

        getResponse().setStatus(Status.SUCCESS_ACCEPTED);
        StringBuffer sb = new StringBuffer();
        ScanRequestAck ack = new ScanRequestAck();
        ack.statusURL = "http://localhost:8080/status/2713"; …
Run Code Online (Sandbox Code Playgroud)

postgresql rest json restlet

5
推荐指数
1
解决办法
2万
查看次数

Tastypie ajax POST obj_create - 如何返回json

我发送一个创建新用户的POST,这是有效的.

我的问题是我如何回到例如创建用户的pk到ajax响应?

         $.ajax({
                url: 'http://localhost:8080/api/v1/create/user/',
                type: 'POST',
                contentType: 'application/json',
                data: '{"uuid": "12345"}',
                dataType: 'json',
                processData: false,
                success: function (r) {
                    console.log(r)
                },
            });

def obj_create(self, bundle, request=None, **kwargs):
        try:
            user = User.objects.create_user(bundle.data['uuid'],'1')
            user.save()


        except:
            pass
        return bundle
Run Code Online (Sandbox Code Playgroud)

django tastypie

4
推荐指数
1
解决办法
3354
查看次数

标签 统计

rest ×2

django ×1

http ×1

json ×1

postgresql ×1

restlet ×1

tastypie ×1

web ×1

web-services ×1