api-design

Why does the Linux Open system call not need a buffer size parameter for the path?

柔情痞子 提交于 2021-02-17 06:25:26
问题 Why does the open system call not need a buffer size parameter like the write system call does? How do these two system calls treat their string parameters differently? Does the open system call assume a zero-terminated string for the path parameter while the write system call does not? If so why the inconsistency? Why not make all (or none) of the system calls that use strings / arrays require a size parameter? 回答1: UNIX was developed as an operating system for programs written in assembly,

Is there a way to secure an API without login based authentication?

落花浮王杯 提交于 2021-02-08 10:18:25
问题 I'm currently developing an API for a website, but the website doesn't require logging in to use, so the API has to work without individual user authentication. The goal is to prevent the API from being used by a 3rd party. Is there a way to protect the API to only be used by my website, without using login authentication to prevent 3rd parties from calling the backend service. I've looked into CORS, but it doesn't seem like a strong guarantee. Another thought was a rotating API key. What is

Respond 200 with error or the response code as the error code

删除回忆录丶 提交于 2021-02-08 02:15:30
问题 So, being a developer I have a very basic question, in a REST standard we have 100's of error code for specific reason like: 4xx if resource related 5xx if exception occurred in server and many more. Now when it comes to the implementation there are situations when we return 404 directly as the response status code with the error message in the response body . With this approach there is a thing that I think a bit confusing, what if the URI itself is never being made , that means suppose /a/b

Respond 200 with error or the response code as the error code

微笑、不失礼 提交于 2021-02-08 02:14:02
问题 So, being a developer I have a very basic question, in a REST standard we have 100's of error code for specific reason like: 4xx if resource related 5xx if exception occurred in server and many more. Now when it comes to the implementation there are situations when we return 404 directly as the response status code with the error message in the response body . With this approach there is a thing that I think a bit confusing, what if the URI itself is never being made , that means suppose /a/b

Respond 200 with error or the response code as the error code

家住魔仙堡 提交于 2021-02-08 02:13:54
问题 So, being a developer I have a very basic question, in a REST standard we have 100's of error code for specific reason like: 4xx if resource related 5xx if exception occurred in server and many more. Now when it comes to the implementation there are situations when we return 404 directly as the response status code with the error message in the response body . With this approach there is a thing that I think a bit confusing, what if the URI itself is never being made , that means suppose /a/b

How can I make method chaining fluent in C?

Deadly 提交于 2021-02-05 05:46:06
问题 There is an existing C API that looks like this: //data typedef struct {int properties;} Widget; //interface Widget* SetWidth(Widget *const w, int width){ // ... return w; } Widget* SetHeight(Widget *const w, int height){ // ... return w; } Widget* SetTitle(Widget *const w, char* title){ // ... return w; } Widget* SetPosition(Widget *const w, int x, int y){ // ... return w; } The first parameter is always a pointer to the instance, and the functions that transform the instance always return

Ways to keep a Typescript library API declaration coherent with its implementation?

*爱你&永不变心* 提交于 2021-01-29 19:02:19
问题 Project structure description In my library named mylib I have an API declarartion file src/mylib.d.ts written by hand. There is a reason for write it manually: I want to design an API first and then to implement it (while the tsc with --declaration flag does the opposite - it generates an API declaration from implementation). Content of src/mylib.d.ts : declare module "mylib" { export interface Animal { walk(): void; } export class Dog implements Animal { constructor(name: string); walk(run?

How to design REST API for export endpoint?

可紊 提交于 2021-01-21 08:03:05
问题 I am designing a REST API and am running into a design issue. I have alerts that I'd like the user to be able to export to one of a handful of file formats. So we're already getting into actions/commands with export , which feels like RPC and not REST. Moreover, I don't want to assume a default file format. Instead, I'd like to require it to be provided. I don't know how to design the API to do that, and I also don't know what response code to return if the required parameter isn't provided.

What HTTP response code to use for failed POST request?

﹥>﹥吖頭↗ 提交于 2021-01-21 07:12:45
问题 What HTTP response code should be returned when a POST request was not successful and a request body was correctly formatted? For successful POST request i am using 201 - Created, but there is no equivalent not created code. I am thinking either 400 - bad request but that would actually point user that a request is poorly formatted or 304 - not modified. 回答1: What HTTP response code should be returned when a POST request was not successful and a request body was correctly formatted? If you

TypeORM: update item and return it

笑着哭i 提交于 2020-12-30 04:55:39
问题 As far as I know, it's a best practice to return an item after it has been updated. TypeORM's updateById returns void , not the updated item though. My question: Is it possible to update and return the modified item in a single line? What I tried so far: await this.taskRepository.updateById(id, { state, dueDate }); return this.taskRepository.findOne({ id }); What I'm looking for: return this.taskRepository.updateById(id, { state, dueDate }); // returns updated task 回答1: I just found out that