{"id":23629796,"url":"https://github.com/willworks/mvcrestful","last_synced_at":"2025-11-08T03:30:34.110Z","repository":{"id":80026004,"uuid":"44297529","full_name":"willworks/MVCRESTful","owner":"willworks","description":"A node MVC web server system with RESTful API","archived":false,"fork":false,"pushed_at":"2015-12-04T09:25:44.000Z","size":21,"stargazers_count":2,"open_issues_count":0,"forks_count":0,"subscribers_count":3,"default_branch":"master","last_synced_at":"2024-12-28T01:18:11.147Z","etag":null,"topics":[],"latest_commit_sha":null,"homepage":null,"language":"JavaScript","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"mit","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/willworks.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null}},"created_at":"2015-10-15T06:17:33.000Z","updated_at":"2019-08-18T16:53:25.000Z","dependencies_parsed_at":"2023-03-14T05:15:13.403Z","dependency_job_id":null,"html_url":"https://github.com/willworks/MVCRESTful","commit_stats":null,"previous_names":[],"tags_count":0,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/willworks%2FMVCRESTful","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/willworks%2FMVCRESTful/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/willworks%2FMVCRESTful/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/willworks%2FMVCRESTful/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/willworks","download_url":"https://codeload.github.com/willworks/MVCRESTful/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":239547410,"owners_count":19657148,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":[],"created_at":"2024-12-28T01:18:14.744Z","updated_at":"2025-02-18T20:40:58.273Z","avatar_url":"https://github.com/willworks.png","language":"JavaScript","funding_links":[],"categories":[],"sub_categories":[],"readme":"# RESTful\nA RESTful web system build with node\n\n### node获取url数据\n\n官方API参考[node URL](http://nodeapi.ucdok.com/#/api/url.html)\n\n\t\t/* 测试代码\n\n\t\t * POST请求\n\t\t   var xmlhttp = new XMLHttpRequest();\n\t\t   var user = 'name=mohit\u0026password=password4\u0026profession=teacher\u0026id=4';\n\t\t   xmlhttp.open('POST','http://localhost:8080/addUser',true);\n\t\t   xmlhttp.setRequestHeader(\"Content-type\",\"application/x-www-form-urlencoded\");\n\t\t   xmlhttp.send(user);\n\n\t\t * GET请求\n\t\t    var xmlhttp = new XMLHttpRequest();\n\t\t    // xmlhttp.open('GET','http://localhost:8080/listUsers');\n\t\t    xmlhttp.open('GET','http://localhost:8080/listUser/1');\n\t\t    xmlhttp.send();\n\n\t\t * PUT请求\n\t\t \tvar xmlhttp = new XMLHttpRequest();\n\t\t \tvar user = 'name=mohit\u0026password=password4\u0026profession=teacher\u0026id=1';\n\t\t \txmlhttp.open('PUT','http://localhost:8080/updateUser/1',true);\n\t\t \txmlhttp.setRequestHeader(\"Content-type\",\"application/x-www-form-urlencoded\");\n\t\t \txmlhttp.send(user);\n\n\t     * DELETE请求\n\t        var xmlhttp = new XMLHttpRequest();\n\t        xmlhttp.open('DELETE','http://localhost:8080/deleteUser/1');\n\t        xmlhttp.send();\n\t        \n\t\t*/\n\n\t\tvar http = require('http'),\n\t\t\tfs = require('fs'),\n\t\t\turl = require('url'),\n\t\t\tquerystring = require('querystring');\n\n\t\thttp.createServer(function (req, res) { \n\n\t\t\t//获取请求方法\n\t\t\tvar method = req.method; \n\n\t\t\t//获取原始请求路径\n\t\t\tvar path = req.url; \n\n\t\t\t// 获取不带参数的路径\n\t\t\tvar pathname = url.parse(path).pathname; \n\n\t\t\t// node path模块自带的pathname.split(path.sep)用于切割路径\n\t\t\t// 但是由于windows和*nix下，具体看http://nodeapi.ucdok.com/#/api/path.html\n\t\t\t// linux上的例子:'foo/bar/baz'.split(path.sep) returns ['foo', 'bar', 'baz']\n\t\t\t// Windows上的例子:'foo\\\\bar\\\\baz'.split(path.sep) returns ['foo', 'bar', 'baz']\n\n\t\t\t// 这里用pathname.split('/')来实现切割各个参数\n\t\t\tpathname = pathname.split('/');\n\n\t\t\t//获取GET/DELETE url传递的参数 通过来获取params.XXX\n\t\t\tvar params = url.parse(req.url).query; \n\t\t\t\tparams = querystring.parse(params);\n\n\t\t\t//获取POST/PUT传递的参数 通过addListener来实现\n\t\t\tvar paramsPost ='';  \n\t\t    req.addListener('data', function(chunk){  \n\t\t        paramsPost += chunk;  \n\t\t    })  \n\t\t    .addListener('end', function(){  \n\t\t        paramsPost = querystring.parse(paramsPost);\n\t\t        console.log(paramsPost);\n\t\t    });\n\n\t\t}).listen(8080, '127.0.0.1'); \n\n\t\tconsole.log('Server running at http://127.0.0.1:8080/');\n\n### RESTful API列表\n\n\n\u003ctable style=\"margin:0 auto\"\u003e \n\t\u003ctbody\u003e\n\t\t\u003ctr\u003e\n\t\t\t\u003cth\u003e序号\u003c/th\u003e\n\t\t\t\u003cth\u003eURI\u003c/th\u003e\n\t\t\t\u003cth\u003eHTTP 方法\u003c/th\u003e\n\t\t\t\u003cth\u003e发送内容\u003c/th\u003e\n\t\t\t\u003cth\u003e结果\u003c/th\u003e \n\t\t\u003c/tr\u003e\n\n\t\t\u003ctr\u003e\n\t\t\t\u003ctd\u003e1\u003c/td\u003e\n\t\t\t\u003ctd\u003elistUsers\u003c/td\u003e\n\t\t\t\u003ctd\u003eGET\u003c/td\u003e\n\t\t\t\u003ctd\u003e空\u003c/td\u003e\n\t\t\t\u003ctd\u003e显示所有用户列表\u003c/td\u003e \n\t\t\u003c/tr\u003e\n\n\n\t\t\u003ctr\u003e\n\t\t\t\u003ctd\u003e2\u003c/td\u003e\n\t\t\t\u003ctd\u003elistUser/id\u003c/td\u003e\n\t\t\t\u003ctd\u003eGET\u003c/td\u003e\n\t\t\t\u003ctd\u003e空\u003c/td\u003e\n\t\t\t\u003ctd\u003e显示用户详细信息\u003c/td\u003e \n\t\t\u003c/tr\u003e\n\n\n\t\t\u003ctr\u003e\n\t\t\t\u003ctd\u003e3\u003c/td\u003e\n\t\t\t\u003ctd\u003eaddUser\u003c/td\u003e\n\t\t\t\u003ctd\u003ePOST\u003c/td\u003e\n\t\t\t\u003ctd\u003eJSON 字符串\u003c/td\u003e\n\t\t\t\u003ctd\u003e添加新用户\u003c/td\u003e \n\t\t\u003c/tr\u003e\n\n\n\t\t\u003ctr\u003e\n\t\t\t\u003ctd\u003e4\u003c/td\u003e\n\t\t\t\u003ctd\u003eupdateUser/id\u003c/td\u003e\n\t\t\t\u003ctd\u003ePUT\u003c/td\u003e\n\t\t\t\u003ctd\u003eJSON 字符串\u003c/td\u003e\n\t\t\t\u003ctd\u003e更新用户\u003c/td\u003e \n\t\t\u003c/tr\u003e\n\n\n\t\t\u003ctr\u003e\n\t\t\t\u003ctd\u003e5\u003c/td\u003e\n\t\t\t\u003ctd\u003edeleteUser/id\u003c/td\u003e\n\t\t\t\u003ctd\u003eDELETE\u003c/td\u003e\n\t\t\t\u003ctd\u003e空\u003c/td\u003e\n\t\t\t\u003ctd\u003e删除用户\u003c/td\u003e \n\t\t\u003c/tr\u003e\n\n\n\n\t\u003c/tbody\u003e\n\u003c/table\u003e\n\n\u003cbr /\u003e\n\n关于PUT和POST的差别，可以看看《HTTP权威指南》，里边提到的是\n\n - PUT：“让服务器用请求的主体部分来创建一个由请求的URL命名的新文档，或者是替换指定URL的文档”\n - POST：“post用于向服务器发送数据，而put用于向服务器上的资源中存储数据，通常POST方法用于HTML中的表单，用户在表单中填好数据之后，点击发送，填好的数据便会发送到服务器，然后由服务器将其送到它要去的地方(例如一个网关程序，然后由这个程序对数据进行处理)”\n\n通过链接来看的话\n\n - PUT：http://localhost:8080/addUser/1 body:'name=mohit\u0026password=password4\u0026profession=teacher\u0026id=4'\n - POST：http://localhost:8080/addUser body:'name=mohit\u0026password=password4\u0026profession=teacher\u0026id=4'\n\n在HTTP规范中对POST和PUT是这样定义的：\n  \n - The POST method isused to request that the origin server accept the entity enclosed in therequest as a new subordinate of the resource identified by the Request-URI inthe Request-Line ...... If a resource has been created on the origin server,the response SHOULD be 201 (Created) and contain an entity which describes thestatus of the request and refers to the new resource, and a Location header.\n  \n - The PUT methodrequests that the enclosed entity be stored under the supplied Request-URI. Ifthe Request-URI refers to an already existing resource, the enclosed entitySHOULD be considered as a modified version of the one residing on the originserver. If the Request-URI does not point to an existing resource, and that URIis capable of being defined as a new resource by the requesting user agent, theorigin server can create the resource with that URI.\n\n大概意思就是，POST全部数据传到服务器处理，而PUT指定了URL上的资源进行操作，但是实际上，最大的差别不是在语义，而是在幂等和非幂等\n\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fwillworks%2Fmvcrestful","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fwillworks%2Fmvcrestful","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fwillworks%2Fmvcrestful/lists"}