A
A
ar52017-03-22 00:06:04
JavaScript
ar5, 2017-03-22 00:06:04

How to build API logic correctly?

Hello, I'm trying to make a small project for myself and I have an interesting question about the API. You need to upload a post with some data and a picture.
I'm doing it with express.js and mongoDB
1. Do I need to do everything in one request? Those. loading picture and all information?
2. Is it necessary to allocate a separate resource for uploading a picture?
3. When I put a picture in static, do I have to wait until the file is fully loaded and then put the data and the path to the file?
Thanks for the clarification.

Answer the question

In order to leave comments, you need to log in

2 answer(s)
E
Evgeny Troinov, 2017-03-22
@tot0ro

1. Not quite the correct statement of the question, are you going to send an image in the request? or how?.
Usually, if you store data in a database, then you first request data from the database, then check the image at the address and send the status about it to the client, if everything is OK, and if an error occurs, then the result of its processing.
2. What do you mean by the word "resource"?
3. Yes, because a situation may arise when the space on the screw runs out and the records will be saved in the database.

D
dativav, 2017-03-22
@dativav

Binary files, yes, it is better to send them separately.
Especially if they are big.

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question