Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Request for additional new feature of REST API: #135

Closed
abeq opened this issue Dec 16, 2022 · 3 comments
Closed

Request for additional new feature of REST API: #135

abeq opened this issue Dec 16, 2022 · 3 comments

Comments

@abeq
Copy link

abeq commented Dec 16, 2022

Hi,

POST with query like as

const query={"query":"SELECT c.fullname AS customer,b.title AS book,(b.price*ob.quantity) AS subtotal,o.id AS order_id \
FROM order_books AS ob \
INNER JOIN books AS b ON ob.book_id=b.id \
INNER JOIN orders AS o ON ob.order_id=o.id \
INNER JOIN customers AS c ON o.customer_id=c.id \
WHERE c.id=1;"};

let postdata = async ()=>{
 const response = await fetch('http://127.0.0.1/api', {
  method:'POST',
  //...snip...
  body:JSON.stringify(query) 
 });
 return response.json();
}

response.json would be:

[{"customer":"Bran Oldy","book":"Take Me With You","subtotal":1.98,"order_id":1},
{"customer":"Bran Oldy","book":"Secrets of a Charmed Life","subtotal":3.2,"order_id":1},
{"customer":"Bran Oldy","book":"The Way We Fall","subtotal":18.1,"order_id":6},
{"customer":"Bran Oldy","book":"The Girl on the Train","subtotal":99,"order_id":9,6},
{"customer":"Bran Oldy","book":"Secrets of a Charmed Life","subtotal":6.4,"order_id":12},
{"customer":"Bran Oldy","book":"Steelheart","subtotal":5.0,"order_id":12},
{"customer":"Bran Oldy","book":"Steelheart","subtotal":5.0,"order_id":15}]

I think it is useful for development.
Please consider it.

@little-brother
Copy link
Owner

little-brother commented Dec 16, 2022

POST have to create a new row (= change a data). So GET is more appropriate verb for it.
But I'm not sure why it can be usefull. Typically API don't allow to execute an arbitrary queries.

@abeq
Copy link
Author

abeq commented Dec 18, 2022

I think this REST server is for development so it is useful on early stage of prototype development (yet appropriate query is not defined). And does this REST server support GET with request body? Typical GET is not for complex query.

@abeq
Copy link
Author

abeq commented Dec 25, 2022

withdrawn

@abeq abeq closed this as completed Dec 25, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants