Where to place forms / alternative views in a RESTful html application?

Suppose the web application for each URI is a good html representation for GET requests and allows updating the base resource through POST / PUT / PATCH / WHATEVER.

How can I expose the various forms that actually allow such requests to be executed from the browser? And more broadly: if I have alternative views (possibly also HTML) for the same resource, where do I put them? It can be argued that such forms can be considered as alternative views, so the choice of the answer to a broader question would be ideal.


Edit: To clarify, my question is not about pure data APIs serving JSON, but about HTML applications like Stackoverflow. For example, you can get a collection of questions under /questions, and this particular object is in /questions24696982, which makes sense. In order to get a form to add a new question, you will need to use https://stackoverflow.com/a/166269/2128 which is not sure that everything is in order. And this is the form of POSTs https://stackoverflow.com/a/3/9129/ which is simply wrong. Fulfilling a GET request to this URL gives 404 (if something should be 405). The form must be POSTING before /questions. However, I would like to know if at least the form URI is acceptable on a RESTful system.

+4
8

-, RESTFull API - API - , ( ) - , , , frontend www.domain, API api.domain.

GET api.domain/questions - Retrieves a list of tickets   
GET api.domain/questions/12 - Retrieves a specific ticket   
POST api.domain/questions - Creates a new ticket  
PUT api.domain/questions/12 - Updates ticket #12  
DELETE api.domain/questions/12 - Deletes ticket #12  
PATCH api.domain/questions/12 - Partially updates ticket #12 #I only want to display that this also exists - i don't really use it...   

: , stackoverflow : api.stackexchange.com

, , , www.domain/questions/ask, api.domain/questions POST. : https://thenewcircle.com/s/post/1221/designing_a_beautiful_rest_json_api_video , .

EDIT: ( )

, , (Json, XML, HTML), Accept-Header.

1:

       URL           REQUEST       ACCEPT HEADER               RESPONSE                      
-----------------------------------------------------------------------------------------
domain/questions      GET        application/json   all questions as json
domain/questions      GET        text/html          the page as html with all questions
domain/questions/ask  GET        text/html          Your html for to add a new question
domain/questions      POST       application/json   Add a new new questions (this would be called from ./ask to add the new questions
domain/questions/ask  GET        application/json   404 Status-Code because on questions/ask you don't have implemented any resource

-2:

       URL              REQUEST     ACCEPT HEADER               RESPONSE                      
-----------------------------------------------------------------------------------------
domain/questions/12       GET      application/json   Shows the questions with the ID 12 as JSON
domain/questions/12       GET      text/html          Shows the HTML representation of your page
domain/questions/12/edit  GET      text/html          Your html for to edit a the question
domain/questions/12       PUT      application/json   Updates the questions with the ID 12 // just to add the PATCH thing.. i don't really use it but if you don't update the whole object you could/should use PATCH instead of PUT :p
domain/questions/12/edit  GET      application/json   404 Status-Code because on questions/ask you don't have implemented any resource

( : , api ( , api - ), @jackweirdy ( - ) - , / . , , , API REST.

EDIT-Section ( ) , , stackoverflow

+5

, , , .

, API, /people/:id, /people/new. a GET url Accept: text/html , - 404, -. ​​ /people/, .

, - , , , ​​ /people/1/update, HTML.

API , , , new update, .

+1

100% RESTful Web- URL-, URL-, .

, PUT, ( Zend Framework 2, ), POST. , PUT questions, PUT questions/{identifier}, URL-.

0

REst , URL-, http- .

"restfull urls" , , Rest. Rest , URL- .

, "restfull", , /form/ 2929929. , , -, REst , , , .

, URL, . . , /questions/ask/submit Rest, , , 2 .

0

, , :

  • HTML- (, , ?)
  • POST/PUT url ( ), (, , ?)

Ruby on Rails - , . Rails In:

HTTP Verb   Path            action      used for
GET        /photos          index       display a list of all photos
GET        /photos/new      new         return an HTML form for creating a new photo
POST       /photos          create      create a new photo
GET        /photos/:id      show        display a specific photo
GET        /photos/:id/edit edit        return an HTML form for editing a photo
PUT        /photos/:id      update      update a specific photo
DELETE     /photos/:id      destroy     delete a specific photo 

HTML- index, new, show edit.

:

POST       /photos/:id        update    update a specific photo
POST       /photos/:id/delete destroy   delete a specific photo

html-.

Rails REST, , .

, , . Java + Spring MVC , HTML- JSP, Velocity, Thymeleaf JSON HTTP- URL (GET /photos/:id.json) , , RoR. , Struts2 (- Java) Django (Python), , .

:

  • (Ruby, Python, Java, PHP, ASP.NET,...)
  • , URL- RESTfull
  • , HTML JSON , HTTP , , /

, .

0

, RESTfull REST.

RESTfull URL-, ,

GET     /persons   : gets a list of all the persons in database
POST    /persons   : adds a new person
GET     /person/1  : gets a person with id 1
PUT     /person/1  : updates person with id 1
DELETE  /person/1  : deletes person with id 1

..

- . HTTP-. , , , HTTP-.

, , . , , restfull . URL-, :

GET     /person/showall  : displays a list of all persons
GET     /person/create   : shows new person form
POST    /person/create   : submits the data to the restfull application via ajax or simillar technology.

..

HTML, Android, iOS ..

, , , URL- , / . .

, URL- , URL-, .

0

-/ .

REST- ( , JSON), , . , , - /.

MV * Model, View * - - , , .

MV * . , Ember.js, , , . , . , , .

, , , , , . , REST/JSON api , .

, URL- 1:1 backend rest api. , . Ember , , URL-, . -. URL- / . URL- , , api . , - /, . , - .

SEO. -. , , , - , , pretender.io , .

REST , , index.html, app.js app.css , .

, CDN. CORS, - REST, .

ember-cli -, Brunch. , , .

API JSON API. , .

0

- , , .

, SEO DOM (, )...

, SPA ( )

.

(HTML, CSS, Javascript, ) , ( REST json/xml).

HTML JQuery/AngularJS/Backbone - JavaScript, "" HTML , JavaScript.

JavaScript RESTful POST PUT ( REST) ​​

, ,

GET /profile/{id}  would be called to pre-populate a profile FORM

PUT /profile/{id}  would be called to update the profile 

** JavaScript FORM, RESTful GET.

** JavaScript FORM POST/PUT RESTful.

, , :

JavaScript RESTful "" HTML.

HTML - ( ) , " ":)

, .

!

PS Find out about Cross-origin Resource Sharing (CORS), if you haven't already. You will probably need this knowledge to properly place your static content on a different server / domain than your dynamic content.

0
source

Source: https://habr.com/ru/post/1548062/


All Articles