API - get info without datatable

API - get info without datatable

Rachel Pfeiffer LeverageRachel Pfeiffer Leverage Posts: 5Questions: 3Answers: 0

If you visit the url of an Editor ajax page, you get an HTML page with json returned.
So for example, my ajax page is "http://localhost:8000/api/students", and I get back

{"data":[{"DT_RowId":"row_2","id":"2","student_id":"1","status":"Pending","lname":"Yanky","fname":"Goldberg","email":"student@tpf.org","phone":"987-654-4334","password":"$2y$10$fIvh6pcMKgHuyAq\/3xr0YOc.fVKwWVG7m0oIPpVsyIiD5GipVyAxK","user_id":"2","gender":null,"city":"Staten Island","state":"NY","country":"USA","religion_born":"Judaism","mother_religion":"Judaism","father_religion":"Judaism","religion_identify_with":null,"jewish_story":null,"created_at":null,"updated_at":null},{"DT_RowId":"row_17","id":"17","student_id":"3","status":"Approved","lname":"Ettel","fname":"Sprat","email":"shmodcast@tpf.org","phone":"845-454-5454","password":"$2y$10$4zsG5TtuSTaNm7jPyDBTs.w8vGbxD1dUIDPRPaKMYM9jbPkjAmO3e","user_id":"17","gender":null,"city":"Staten Island","state":"NY","country":"United States","religion_born":"Judaism","mother_religion":"Judaism","father_religion":"Judaism","religion_identify_with":null,"jewish_story":null,"created_at":"2021-12-28 00:00:00","updated_at":"2022-01-11 08:04:49"}],"options":{"gender":[{"value":"","label":""},{"value":"f","label":"Female"},{"value":"m","label":"Male"}]},"files":[]}

Can I customize this to get the info for a single record? I want to enter "http://localhost:8000/api/students/5" and get back the json for student number 5, and also have the ability to post to that url. Is there documentation for this?

This question has an accepted answers - jump to answer

Answers

  • allanallan Posts: 61,697Questions: 1Answers: 10,102 Site admin
    Answer ✓

    Yes it is possible, but there isn't documentation for that specific application since it isn't needed for Editor to operate normally.

    It sounds like you want to extend Editor's server-side aspect to be a general REST API - is that correct? I assume you are using our Editor libraries for this? If so, you would need to have your controller for the /api/students/{id} route build the Editor instance as normal, but then also add a condition for the specified id.

    Updating the data would be similar. You may wish to allow data to be sent to your REST API in a format other than what Editor would send itself (which is described here) so you may want to restructure the data your API expects into what Editor expects.

    Allan

  • Rachel Pfeiffer LeverageRachel Pfeiffer Leverage Posts: 5Questions: 3Answers: 0

    That is very helpful - thank you so much!

Sign In or Register to comment.