api-design

How to design a RESTful API that queries info about a verb (e.g. a potential POST request)?

半世苍凉 提交于 2020-01-26 02:02:15
问题 I'm learning how to design a RESTful API and I've come across a quandary. Say I have a POST endpoint to perform an action. The action has a certain cost associated with it. The cost depends on what the action is, particularly, on the body of the POST. For example, given these two requests: POST /flooblinate {"intensity": 50, "colorful": true, "blargs": [{"norg": 43}]} POST /flooblinate {"intensity": 100, "colorful": false, "blargs": []} Say the first one costs 500 and the second one costs 740

How to design a RESTful API that queries info about a verb (e.g. a potential POST request)?

孤人 提交于 2020-01-26 02:02:07
问题 I'm learning how to design a RESTful API and I've come across a quandary. Say I have a POST endpoint to perform an action. The action has a certain cost associated with it. The cost depends on what the action is, particularly, on the body of the POST. For example, given these two requests: POST /flooblinate {"intensity": 50, "colorful": true, "blargs": [{"norg": 43}]} POST /flooblinate {"intensity": 100, "colorful": false, "blargs": []} Say the first one costs 500 and the second one costs 740

Why do we need EPOLLRDHUP when EPOLLHUP seems enough?

我的未来我决定 提交于 2020-01-24 03:31:11
问题 According to the linux man page, EPOLLHUP When reading from a channel such as a pipe or a stream socket, this event merely indicates that the peer closed its end of the channel. EPOLLRDHUP Stream socket peer closed connection, or shut down writing half of connection. I can hardly tell any difference between EPOLLHUP and EPOLLRDHUP . To me, whenever EPOLLRDHUP is used EPOLLHUP can be used instead with the same semantics. Am I right? If not, any explanations? 来源: https://stackoverflow.com

Clearer response from BigCommerce

Deadly 提交于 2020-01-15 06:44:09
问题 Can BigCommerce change their API response to be more clear when a program tries to post a shipment that already exists? When posting shipments to BigCommerce, if the shipment already exists, then you receive the following error message. <?xml version="1.0"?> <errors> <error> <status>400</status> <message>The field 'quantity' is invalid.</message> <details> <invalid_reason>The quantity specified is greater than the quantity of the product that is available to ship.</invalid_reason> <available

How to convert an IHttpActionResult (with JSON inside) to an object I can process with LINQ

喜欢而已 提交于 2020-01-14 02:07:26
问题 It might be a noob question or an architectural misunderstanding, but I ask it anyhow because I am out of ideas and search terms: The goal is to implement a controller CountriesController() which is supposed to concatenate the (JSONish) results of two endpoints. Assume I have two endpoints api/allowedCountriesToSell and api/allowedCountriesToBuy which are implemented as CountriesSellController() and CountriesBuyController() respectively. Both of them give back data as JSON which I want to

Does casting a pointer back and forth from size_t or uintptr_t break strict aliasing?

喜你入骨 提交于 2020-01-13 11:32:26
问题 I'm proposing a change to a library whose public API currently looks like this: typedef size_t enh; /* handle */ int en_open(enh *handle) { struct internal *e = malloc(...); *handle = (enh)e; return 0; } int en_start(enh handle) { struct internal *e = (struct internal*)handle; return do_something(e); } Does this usage, casting back and forth to size_t break strict aliasing? For the record, I'm proposing a typical opaque forward declaration of struct internal in the public API, as shown on

What are the possibilities to design an API that needs overloads depending on a generic type?

…衆ロ難τιáo~ 提交于 2020-01-13 06:05:53
问题 In a given class Example<A> I need the following two functions to be available: void doSomething(Supplier<A>) <B> void doSomething(Supplier<B>) What are the possibilities to achieve this? I know the following approaches: give the functions different names use a wrapper-type for the second-definition WrapperType.of(Supplier<B>) use a function that converts Example<A> to Example<B> Are there any other approaches? I dislike 1) as it clutters my API. 2) is really verbose as I have to call said

Designing APIs in Java with top-down approach - Is writing up the Javadoc the best starting point?

跟風遠走 提交于 2020-01-12 01:50:56
问题 Whenever I have the need to design an API in Java, I normally start off by opening up my IDE, and creating the packages, classes and interfaces. The method implementations are all dummy, but the javadocs are detailed. Is this the best way to go about things? I am beginning to feel that the API documentation should be the first to be churned out - even before the first .java file is written up. This has few advantages: The API designer can complete the design & specification and then split up

What's the point of DSLs / fluent interfaces

﹥>﹥吖頭↗ 提交于 2020-01-11 16:40:31
问题 I was recently watching a webcast about how to create a fluent DSL and I have to admit, I don't understand the reasons why one would use such an approach (at least for the given example). The webcast presented an image resizing class, that allows you to specify an input-image, resize it and save it to an output-file using the following syntax (using C#): Sizer sizer = new Sizer(); sizer.FromImage(inputImage) .ToLocation(outputImage) .ReduceByPercent(50) .OutputImageFormat(ImageFormat.Jpeg)

What would be a good API format for “NOT IN” clause?

左心房为你撑大大i 提交于 2020-01-07 07:59:10
问题 I have a query API against my service, that looks like this (JSON-ish format): { filter: { attribute1: [val11] ,attribute2: [val21, val22] } } means effectively, select data WHERE attribute1 IN ("val11") AND attribute2 in ("val21", "val22") in SQL-ish syntax. I need to expand this API to be able to express NOT IN predicate, and I'm at a loss as to what a good way to do so would be. The only thing I can possibly think of is to add a second "filter_not_in" key in the request API, that would