逻辑和物理网址 [英] Logical and Physical URLs

查看:114
本文介绍了逻辑和物理网址的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

这个问题是对我之前的问题的扩展:这个Web服务Restfull是为了试图更好地理解Rest Web Service的概念。
我几乎读了所有关于Rest的内容,但是我无法理解某个Web Service是否为Rest,或者为什么它不是。我看到它的方式,一切都是,并不是休息,取决于观点......



我读了一篇非常有趣的文章,了解什么是休息。我读了休息并不使用物理网址,而是逻辑网址。



我记得有一次我开发了一个iOS应用程序,我们必须注册/订阅用户等,我被告知将一个Post HTTP请求发送到我们的服务器,使其看起来像这样: www.myServer / devices / device / register 。在这个请求的主体中,我拥有服务器所需的所有json格式的信息。那时候,我的服务器是一个黑匣子,所以我甚至不在乎这个链接是什么意思或者它是如何生成的。但我知道这是一个网络休息服务。



本月我开始开发移动混合应用程序,在那里我开始使用原生代码+ jquery mobile开发前端,后端为php + mysql。我在这里或多或少有相同的场景,用户需要在某个事件中订阅。当他按下一个按钮来订阅一个特定的事件时,我发送一个带有ajax调用和一个json文件的http post请求到一个特定的php脚本,并且该脚本相应地在数据库中写入/更新/删除。



调用如下所示:

  $。ajax({
类型:POST,
url:http://192.168.4.113/Server_CityInfo/subscribe.php,
data:data,
contentType:application / json; charset = utf-8,
// dataType:json,
success:function(response){
$ .mobile.changePage(dialog.html,{role:dialog });
},
error:function(xhr,status,message){alert(Status:+ status +\\\
Message:+ message);}
} );

正如您所看到的,我使用物理网址来指向我的PHP脚本来执行此操作。即使是用户所在的html页面,也是一个物理页面!是一个像myUrl.com/eventX这样的页面。



这是否意味着我正在构建的这个Web服务不是Rest?



去年他们是如何将我指向逻辑网址的,我只能指向物理php脚本?我知道他们的服务器是在Java中,也许这就是为什么网址不看实体?

而在一天结束时可以说我有100个不同的事件,即用户可以订阅。当然,我不会做一个100个静态html页面。但我会做1动态生成的HTML页面。但是,该页面的链接仍然是物理的,如 mySite.com/event.html 。我知道让url看起来合乎逻辑的唯一方法是当你在一个文件夹中有一个index.html文件,并且你指向那个文件夹,这样url看起来像 myWebsite.com/myFolder

所以这里的问题是,如何构建一个逻辑url,这是什么使服务Restfull?



编辑






另外一个我读了很多的东西是Rest使用URL来描述资源和不是操作!虽然我不明白。对于我的web服务中的所有内容,我都使用Post Request。我想要例如订阅一个用户到一个事件,我在url my.server.com/subscribe.php 发出一个post请求,并且在这个请求的主体中我有一个json文件,其中包含用户的 id 事件名称



当我想注册一个用户时,我在url my.server.com/register.php 和一个json在主体中发布了一个post请求用户的 id >我会尽我所能地解释REST。



REST满网页服务基于两个因素:


  1. 网址 - 网址应该基于资源。例如:/ app / students,/ app / students / {id}

  2. 方法 - 该方法定义要对url执行的操作。像


    • GET - 获取资源
    • PUT - 插入记录

    • POST 记录

    • 删除 - 删除记录


有一些方法可以使用PHP实现宁静的URL请参阅这里


This question is as an extension to my previous question here: "Is this web service Restfull" to an attempt to better understand the concept of a Rest Web Service. I read almost everything there is to be read about Rest and yet i am not able to understand if a certain Web Service is Rest or not , or why its not. The way i see it , everything is and is not Rest depending on the point of view...

I read in a very interesting article something that may at last make me understand what is Rest. I read that Rest doesnt use physical urls but logical ones.

I remember once i was developing an iOS application where we had to register/subscribe a user etc and i was told to make a certain Post HTTP request to our server to a URL that looked like this: www.myServer/devices/device/register. In the body of this request i had all the information in json format that the server needed. By that time the server for me was a black box so i didnt even care what this link meant or how it was generated. But i knew it was a web Rest service.

This month i started devepong a mobile hybrid app , where i started to develop in native code + jquery mobile for the front end , and php + mysql for the back end. I have more or less the same scenario here where the user needs to subscribe in an event or not. When he presses a button to subscribe to a specific event , i make an http post request with ajax call and a json file in the body , to a specific php script and that script writes/updates/deletes in the database accordingly.

The call looks something like this :

$.ajax({
                         type: "POST",
                         url: "http://192.168.4.113/Server_CityInfo/subscribe.php",
                         data: data,
                         contentType: "application/json; charset=utf-8",
                         //dataType: "json",
                         success: function(response) {
                             $.mobile.changePage( "dialog.html", { role: "dialog" } );
                         },
                         error: function(xhr, status, message) { alert("Status: " + status + "\nMessage: " + message); }
                    });

As you see i do use a physical url , to point to my php script to take that action. Even the html page that the user is in , is a physical page! Is a page like myUrl.com/eventX .

Does that mean that this web service i am building is not a Rest one?

How did they last year point me to logical URLs and i can only point to physical php scripts? I know that their server was in java , maybe thats why the urls dont look physical?

And in the end of the day lets say i have a 100 different events that the user can subscribe to. Of course i wouldnt make a 100 static html pages. BUT i would make 1 html page that would be dynamically generated. But still the link to that page would be physical like mySite.com/event.html. The only way i know to make a url to look logical is when u have an index.html file inside a folder and you point to that folder so that the url looks like myWebsite.com/myFolder.

So the question here is , how to build a logical url and is this what makes a service Restfull?

EDIT


Another thing that i read a lot is that Rest is using urls that describe resources and not operations!. Again though i fail to understand. For everything in my web service i use Post Request. I want for example to subscribe a user to an event , i make a post request at the url my.server.com/subscribe.php and in the body of this request i have a json file with the id of the user and the event name .

When i want to register a user i make a post request at the url my.server.com/register.php and a json in the body with the id of the user.

Is this scenario Rest and if not what is missing?

解决方案

I will try to explain REST as I understand.

RESTfull webservices are based on two factors:

  1. URLS - The urls should be based on the resources. Like: /app/students, /app/students/{id}
  2. METHODS - The method defines the operation to be done on the url. Like

    • GET - To get resource
    • PUT - To insert a record
    • POST - To update a record
    • DELETE - To delete a record.

There are ways to achieve restful urls using PHP see the answer here

这篇关于逻辑和物理网址的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆