api-design

Writing functions that accept both 1-D and 2-D numpy arrays?

跟風遠走 提交于 2019-12-05 11:47:38
问题 My understanding is that 1-D arrays in numpy can be interpreted as either a column-oriented vector or a row-oriented vector. For instance, a 1-D array with shape (8,) can be viewed as a 2-D array of shape (1,8) or shape (8,1) depending on context. The problem I'm having is that the functions I write to manipulate arrays tend to generalize well in the 2-D case to handle both vectors and matrices, but not so well in the 1-D case. As such, my functions end up doing something like this: if arr

find-or-create idiom in REST API design?

徘徊边缘 提交于 2019-12-05 09:53:07
问题 say we have a 'user' resource with unique constraint on 'name'. how would you design a REST API to handle a find-or-create (by name) use case? I see the following options: option 1: multiple requests client: POST /user {"name":"bob"} server: HTTP 409 //or something else client: GET /user?name=bob server: HTTP 200 //returns existing user option 2: one request, two response codes client: POST /user {"name":"bob"} server: HTTP 200 //returns existing user (in case user is actually created, return

Why is JavaMail Transport.send() a static method?

二次信任 提交于 2019-12-05 05:23:00
I'm revising code I did not write that uses JavaMail, and having a little trouble understanding why the JavaMail API is designed the way it is. I have the feeling that if I understood, I could be doing a better job. We call: transport = session.getTransport("smtp"); transport.connect(hostName, port, user, password); So why is Eclipse warning me that this: transport.send(message, message.getAllRecipients()); is a call to a static method? Why am I getting a Transport object and providing settings that are specific to it if I can't use that object to send the message? How does the Transport class

Naming java methods that return streams

*爱你&永不变心* 提交于 2019-12-05 05:13:14
Is there naming convention for methods that return Stream? The only mention I found is this answer on S.O (last paragraph), but I don't see what is it based on. Since I wrote that paragraph I feel compelled to answer. :-) Suppose you have a class that represents an aggregation of things of a single type, and you want to return a Stream of them to the caller. If it's totally unambiguous as to what you're returning, you might just as well call the method stream() . There are a lot of methods in the JDK named stream() that return a stream of the obvious type. Sometimes what you're returning is

Link to another resource in a REST API: by its ID, or by its URL?

纵然是瞬间 提交于 2019-12-05 05:12:36
I am creating some APIs using apiary , so the language used is JSON. Let's assume I need to represent this resource: { "id" : 9, "name" : "test", "customer_id" : 12, "user_id" : 1, "store_id" : 3, "notes" : "Lorem ipsum example long text" } Is it correct to refer to other resources by their IDs ( 12 , 1 , 3 ), or I should specify the URL of these resources (i.e. /customers/12 , /users/1 , /stores/3 )? I am not using HATEOAS and I am a bit confused. stakx supports GoFundMonica DO include absolute entity URIs in your responses (such as /customers/12 or even http://www.example.com/customers/12 ).

iOS consuming API design

岁酱吖の 提交于 2019-12-05 03:26:32
问题 I am going to develop an iOS app for a web application. (The web app uses code igniter) I am going to create an API Service that the iOS app will consume. I am thinking of creating an api version, so when the web api changes, the iOS app will know. Concerns: iOS app will need to be updated when web application api changes (unless I keep legacy api available..Is this a good option) If iOS app is updated when web app api is NOT updated this will cause a problem too Should my iOS app specify the

Naming a dictionary structure that stores keys in a predictable order?

孤街浪徒 提交于 2019-12-05 01:43:37
Note: Although my particular context is Objective-C, my question actually transcends programming language choice. Also, I tagged it as "subjective" since someone is bound to complain otherwise, but I personally think it's almost entirely objective. Also, I'm aware of this related SO question , but since this was a bigger issue, I thought it better to make this a separate question. Please don't criticize the question without reading and understanding it fully. Thanks! Most of us are familiar with the dictionary abstract data type that stores key-value associations, whether we call it a map,

Strings or URI in .NET APIs?

早过忘川 提交于 2019-12-05 00:59:54
I am writing an .NET wrapper API for the Netflix API. At this point I can choose to represent URLs as either strings or URI objects. Seems to me there is a good case for both. So if you were using an API, which would you prefer? The below quote is from: Framework Design Guildelines I highly recommend this book to anyone developing frameworks on .Net Do use System.Uri to represent URI / URL data. (For Parameters, properties, and return values) System.Uri is a much safer and richer way of representing URIs. Extensive manipulation of URI-related data using plain strings has been shown to cause

Is an API endpoint that differentiates what resources to return based on user credentials RESTful and good URI design?

爱⌒轻易说出口 提交于 2019-12-05 00:27:28
Important note The focus of this question is on API endpoints that differentiate which resources are returned depending who authenticates , e.g. Alice gets resource A and B returned, and Bob gets resource X and Y. It is NOT about differentiating the representation of resources returned. All the endpoints return JSON representations of resources. Preface Please consider the following three potential API endpoint designs, all returning thing resources of a user. Endpoint A GET /things If authentication credentials for <user_x> are provided with the request, it returns thing resources that

Why can't AtomicBoolean be a replacement for Boolean?

雨燕双飞 提交于 2019-12-04 22:15:00
The Oracle JDK Javadoc for AtomicBoolean states: https://docs.oracle.com/javase/8/docs/api/java/util/concurrent/atomic/AtomicBoolean.html A boolean value that may be updated atomically. See the java.util.concurrent.atomic package specification for description of the properties of atomic variables. An AtomicBoolean is used in applications such as atomically updated flags, and cannot be used as a replacement for a Boolean. A colleague and I were trying to figure out a use-case where the AtomicBoolean can't be a substitute and the only thing we can think of is that there are methods the Boolean