How should I answer this interview question? [closed] - api

Closed. This question needs to be more focused. It is not currently accepting answers.
Want to improve this question? Update the question so it focuses on one problem only by editing this post.
Closed 1 year ago.
Improve this question
I found this interview question for a company I'm interested in joining soon.
Consider that you have an API that is called from the UI to display some data using pagination. How would you change the API call if for a non UI client you need to retrieve all data at once without pagination (petabytes of data)?
How would you answer this?

Preface
Firstly, this is not a question for StackOverflow. This question is better suited for software engineering Stack Exchange. Secondly, my answer would be "I don't recommend sending petabytes of data from and HTTP request". However I will attempt to give the answer.
Chunked Transfer Encoding
The only acceptable answer to this question is to enable chunking. Essentially chunking allows you to retrieve an unlimited amount of data through and HTTP call by dividing the stream into non-overlapping chunks. The chunks are received independently of each other and the connection is managed appropriately. To enable this in an http reuqest/response you can utilize the following header
Transfer-Encoding: chunked
There are a variety of optional trailing headers that can be supplied
chunked-body = *chunk
last-chunk
trailer-part
CRLF
chunk = chunk-size [ chunk-ext ] CRLF
chunk-data CRLF
chunk-size = 1*HEXDIG
last-chunk = 1*("0") [ chunk-ext ] CRLF
chunk-data = 1*OCTET ; a sequence of chunk-size octets
Chunking became part of the standard in HTTP1.1 so this will be ineffective on HTTP1.0
However, if the issue is the size of the response you would need to implement chunking server side not as part of the client. I feel as though this is a misunderstanding of chunking on the interviewers part ( because I can't imagine what else they would be referring to ).

Related

How to consume data from url [closed]

Closed. This question needs details or clarity. It is not currently accepting answers.
Want to improve this question? Add details and clarify the problem by editing this post.
Closed last year.
Improve this question
I have url address which accept data from 3rd party server. How can I consume the data from that url? I know that this url accept only post request. So how I can I receive that data in my kotlin app?
This is usually done by using an HTTP client library, so you can more easily convert payloads etc.
There are many HTTP clients to pick from. Among them are Ktor client (Kotlin-first, coroutine-based), Retrofit (very classic on Android), or even the built-in JDK11 HttpClient (although this one is not very Kotlin-friendly), but also many others.
If your code is multiplatform, Ktor would be a particularly good choice.

Multiple API variations or 1 is enough? [closed]

Closed. This question is opinion-based. It is not currently accepting answers.
Want to improve this question? Update the question so it can be answered with facts and citations by editing this post.
Closed 1 year ago.
Improve this question
So my friend needed to develop new API for creating item, so he developed:
POST /new/item
POST /item/new
PUT /new/item
PUT /item/new
All of them call the same underlying function and accept same parameters.
I recommended that he uses only 1 instead of 4, but he says that there is no down side and he's giving the option for anyone who wants to integrate with this API to use whatever personal variation they like.
Question: Is it really that there is no down side by doing this in the long run?
There is no downside in regards to functionality, but an API with redundant endpoints will probably be
Harder to maintain. If a change to the endpoint is needed, it may have to be made four times depending on the setup
Confusing for users of the API. While I imagine it's the intention behind this setup to catch typos in URLs and still allow the API to work, documentation on the endpoints will be bloated and harder to read
Lacking consistent naming. Ideally, there is a logic behind how endpoints are named, allowing users to infer what an endpoint does by its name and verb (GET, POST etc). Having multiple naming schemes makes it harder to understand the naming.
There is no meaningful upside to making redundant endpoints, and I would recommended to use POST /item for creating a new item.

When you type data into a form when is it encrypted? [closed]

Closed. This question needs to be more focused. It is not currently accepting answers.
Want to improve this question? Update the question so it focuses on one problem only by editing this post.
Closed 4 years ago.
Improve this question
This is a theory based question as opposed to any code related question.
I'm trying to establish how data is encrypted and differences client side to server side.
Is the data encrypted when it is added to the database/server?
Or are we just relying on data to be secure due to HTTPS which surely does not apply when the data is transmitted from the form to the database? or does it?
What kind of encryption is mostly used these days?
The data is not encrypted in the client. When HTTPS is used all data is encrypted during transport over the Internet. When the server application receives the data is has already been decrypted. If you need to store the data the server app will need to perform that encryption.
By this question it is clear you do not understand security so you are not ready to create a system that needs security. The solution is to hire a security professional to help you seeding the security. Security is very difficult to get correct and your users rely on and expect a secure system, please provide that.

Send data from one Wemos to another [closed]

Closed. This question needs to be more focused. It is not currently accepting answers.
Want to improve this question? Update the question so it focuses on one problem only by editing this post.
Closed 6 years ago.
Improve this question
I have 2 Wemos d1(retired) boards. I just simply need to send some data or a letter from one to the other. I searched the web deeply and found some complicated NodeMCU stuff and so on. Even though I could send data when I flashed NodeMCU to my Wemos, it was useless because my project is about arduino. I need to work with Arduino IDE. There is also a way to create a WebServer on one of the wemos and then deal with html files. But isn't it so complicated for just sending a couple of bytes? I don't need any webserver or html page. So please help me.
So, just use basic TCP socket communication. Assign one of them as a server. Here are libraries to use for arduino :
https://github.com/esp8266/Arduino/blob/master/libraries/ESP8266WiFi/src/WiFiServer.cpp
https://github.com/esp8266/Arduino/blob/master/libraries/ESP8266WiFi/src/WiFiClient.cpp
Here is a WiFiClient example :
https://github.com/esp8266/Arduino/blob/master/libraries/ESP8266WiFi/examples/WiFiClientBasic/WiFiClientBasic.ino
Here is a WiFiServer example :
how create TCP server by ESP8266?

Binary serialisation of Rust data strucutures [closed]

Closed. This question is opinion-based. It is not currently accepting answers.
Want to improve this question? Update the question so it can be answered with facts and citations by editing this post.
Closed 7 years ago.
Improve this question
What is the current state of serialisation-to-binary in Rust?
I have some large (1-10MB) data structure to be sent across a network, and don't want to encode them as JSON or hex (the two serialisers I have found).
I have found #[repr(packed)]. Is this what I should use, or is there something more portable?
#[repr(packed)] only makes your data small. It does not offer any format guarantees or serialization help.
You have a few choices here (ordered by my opinion from best to worst solution):
You can use the Cap'n proto implementation for Rust
https://github.com/dwrensha/capnproto-rust
It's not really serialization, more of a forced format for structs that are then sent over the network without any conversion
fast
You could write your own Serializer and Deserializer.
you have full control over the format
runtime overhead for every single datum
you need to implement lots of stuff
You can transmute your structs to a [u8] and send that
probably the fastest solution
you need to make sure that the compiler for the program on both sides is exactly the same, otherwise the formats don't match up.
Someone evil may send you bad data. When you transmute that back, you get buffer overflows and stuff
references in your data-structure will cause wild pointers and undefined behaviour
Don't use references