api-design

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

时间秒杀一切 提交于 2019-12-04 15:40:30
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 function often and static imports are very unusual outside of testing code. 3) is very explicit about the

How to handle sensitive properties in a RESTful API (such as passwords, credit cards, etc)

僤鯓⒐⒋嵵緔 提交于 2019-12-04 14:17:19
Working on a REST framework that will support multiple hypermedia types and authentication. One thing I'm not really sure how to handle are sensitive values in the resources. For instance, if I were to include user management in the API, I would need a way to expose to the client that there was a field for the password, but not show the actual password hash. Same thing with a credit card. If I don't, it would violate the hypermedia constraint as knowledge of the fields would become out of band, and make my HATEOAS broken. Here's an actual use case that I've encountered: The project is a

Choosing between package:html, dart:html, dart:io (class HttpClient) and package:http APIs to fetch HTTP resources

拟墨画扇 提交于 2019-12-04 12:19:36
I realized that currently there are at least three "official" Dart libraries that allow me to perform a HTTP request. What is more, three of those libraries (dart:io (class HttpClient), package:http and dart:html) have each a different, incompatible API. As of today, package:html does not offer this functionality, but on its GitHub page I found it aims for 100% API compatibility with dart:html, so these methods will be added there eventually. Which package provides the most future proof and platform independent API to issue a HTTP request in Dart? Is it package:http? import 'package:http/http

404 Not Found or Bad Request?

岁酱吖の 提交于 2019-12-04 10:20:09
问题 Let's say that we have the following REST call: GET api/companies/5 (get company with id 5) If company '5' doesn't exist, we would typically return a 404 Not Found response. But now, let's take this call: GET api/companies/5/invoices/10 (get invoice 10 from company 5) Now, if company '5' doesn't exist, do we still return a 404 Not Found ? Or should a 404 only be returned if the outer most resource can not be found (invoice 10, in this case). Would Bad Request perhaps be a better option? 回答1:

Query String vs Resource Path for Filtering Criteria

…衆ロ難τιáo~ 提交于 2019-12-04 06:35:51
Background I have 2 resources: courses and professors . A course has the following attributes: id topic semester_id year section professor_id A professor has the the following attributes: id faculty super_user first_name last_name So, you can say that a course has one professor and a professor may have many courses. If I want to get all courses or all professors I can: GET /api/courses or GET /api/professors respectively. Quandary My quandary comes when I want to get all courses that a certain professor teaches. I could use either of the following: GET /api/professors/:prof_id/courses GET /api

RESTful API and bulk operations

|▌冷眼眸甩不掉的悲伤 提交于 2019-12-04 05:58:14
I have a middle tier which performs CRUD operations on a shared database. When I converted the product to .NET Core I thought I'd also look at using REST for the API as CRUD is supposed to be what it does well. It seems like REST is a great solution for single record operations, but what happens when I want to delete, say, 1,000 records? Every professional multi-user application is going to have some concept of Optimistic Concurrency checking: you can't have one user wipe out the work of another user without some feedback. As I understand it, REST handles this with the HTTP ETag header record.

What http return code should be if no data available

拟墨画扇 提交于 2019-12-04 05:21:24
For example i have an api method /api/orders.getOrders which actually always exists. If this method returns no data in following format, should i send 404 or 200 http response code? { "orders":[] } 200 is correct. From RFC 7231 The 4xx (Client Error) class of status code indicates that the client seems to have erred. The 404 (Not Found) status code indicates that the origin server did not find a current representation for the target resource In your case, the client did not make a mistake in asking for the resource; the origin server did find a current representation of the resource, so 404

Best way to create REST API for long lasting tasks?

放肆的年华 提交于 2019-12-04 02:04:47
Suppose I have 2 servers. The first is a service that provides some computations, which can last long time (minutes to hours). The second server will use this service to have some data computed. I'm trying to design a REST API for the first server and so far so good. But I'd like to hear some opinion on how to model notifications when the long lasting task is finished. I considered 2 approaches so far: Polling - the second server will ask every now and then about the result. Callback - Second server will setup an uri for the first one to call after it is done. But this smells a bit in REST API

Should Health Checks call other App Health Checks

大城市里の小女人 提交于 2019-12-04 00:52:23
问题 I have two API's A and B that I control and both have readiness and liveness health checks. A has a dependency on B. A /foo - This endpoint makes a call to /bar in B /status/live /status/ready B /bar /status/live /status/ready Should the readiness health check for A make a call to the readiness health check for API B because of the dependency? 回答1: Service A is ready if it can serve business requests. So if being able to reach B is part of what it needs to do (which it seems it is) then it

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

99封情书 提交于 2019-12-03 23:20:50
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.ndim == 1: # Do it this way else: # Do it that way Or even this: # Reshape the 1-D array to a 2-D array