As of May 31, 2023, we have updated our Code of Conduct.

Questions tagged [web-api]

Specific APIs that communicate over web protocols, such as ASP.net Web API, as well as APIs that are exposed to web pages for network communication or apps for device communication

Filter by
Sorted by
Tagged with
95 votes
15 answers
18k views

Should we design our code from the beginning to enable unit testing?

There's a debate going on in our team at the moment as to whether modifying code design to allow unit testing is a code smell, or to what extent it can be done without being a code smell. This has ...
Lee's user avatar
  • 1,101
70 votes
4 answers
27k views

Why PATCH method is not idempotent?

I was wondering about this. Suppose I have a user resource with id and name fields. If I want to update a field I could just do a PATCH request to the resource like this PATCH /users/42 {"name&...
seldon's user avatar
  • 952
58 votes
2 answers
50k views

Is performance the only reason not to use SignalR (websockets) entirely in lieu of a traditional REST API?

I have used SignalR to achieve real-time messaging functionality in several of my projects. It seems to work reliably and is very easy to learn to use. The temptation, at least for me, is to abandon ...
tacos_tacos_tacos's user avatar
49 votes
12 answers
24k views

How do I manage the technical debate over WCF vs. Web API?

I'm managing a team of like 15 developers now, and we are stuck at a point on choosing the technology, where the team is broken into two completely opposite teams, debating over usage of WCF vs. Web ...
Saeed Neamati's user avatar
42 votes
7 answers
43k views

Why do people do REST API's instead of DBAL's?

At the past two companies, I've been at, REST API's exist for querying data via webapp - i.e. instead of having the webapp do SQL directly it calls a REST API and that does the SQL and returns the ...
neubert's user avatar
  • 558
42 votes
1 answer
7k views

How to design a REST API that can "prompt" the client about long-running operations?

Say you were to develop a REST API that provides access to a set of complex, long-running, operations. The typical paradigm for an API like this (as I understand it) usually involves (the client) ...
meci's user avatar
  • 531
41 votes
3 answers
44k views

Should we call Web API from MVC application in same solution?

I am working on a project in MVC that has mobile application so one thing is clear that we have to use Web API so it can used in mobile application. After creating API when we started to develop Web ...
Ruchir Shah's user avatar
40 votes
8 answers
139k views

Use empty string, null or remove empty property in API request/response

When transferring object through an API, as in schemaless JSON format, what is the ideal way to return non-existent string property? I know that there are different ways of doing this as in examples ...
imel96's user avatar
  • 3,468
33 votes
5 answers
30k views

Should I check if something exists in the db and fail fast or wait for db exception

Having two classes: public class Parent { public int Id { get; set; } public int ChildId { get; set; } } public class Child { ... } When assigning ChildId to Parent should I check first if ...
Konrad's user avatar
  • 1,499
33 votes
4 answers
36k views

Why is there no WSDL type support for Web Api?

So I am just getting started with .Net WebApi and one thing that I am noticing straight away is that there is no Contract defining how the API looks and should be consumed (Request/Responses from each ...
shenku's user avatar
  • 476
31 votes
2 answers
19k views

Role-based REST API?

I'm building a REST API for which several users with different roles will have access to the resources it contains. To keep the scope simple let's take the "student/teacher/class" domain: GET /...
Casper Jensen's user avatar
27 votes
6 answers
6k views

Is it ok to have validation layer before access control layer

I am creating an API strcutured web application and in this application we have different layers which are doing their own job. First layer is Validation layer which validate user input and if it ...
Muhammad's user avatar
  • 399
26 votes
3 answers
9k views

RESTful API: HTTP verbs with shared or specific URLs?

While creating a RESTful API, should I use HTTP Verbs on the same URL (when it's possible) or should I create an specific URL per action? For example: GET /items # Read all items GET /...
53777A's user avatar
  • 1,706
26 votes
3 answers
70k views

Best practice for REST API call with many parameters

I have a REST API with GETs operations which receive a (long) list of parameters (8 parameters, for example). The aim of this operation is to search and filter elements. Which is the best practice to ...
Jose Alonso Monge's user avatar
21 votes
2 answers
11k views

Isn't CQRS overengineering?

I still remember good old days of repositories. But repositories used to grow ugly with time. Then CQRS got mainstream. They were nice, they were a breath of fresh air. But recently I've been asking ...
SiberianGuy's user avatar
  • 4,733
20 votes
1 answer
12k views

Why do Microsoft's libraries depend on Newtonsoft.Json?

This had probably started way back when Microsoft created ASP.NET Web API library, at least that's when I remember it if I am not mistaken. Anyway, since then, its HTTP packages started depending on ...
paulius_l's user avatar
  • 319
18 votes
5 answers
29k views

Is it bad practice to use hyphens in JSON keys?

I see a lot of questions revolving around accessing JSON keys that use hyphens (kebab-case), but now I find myself wondering should I just stick to camelCase or snake_case in my keys. I know hyphens ...
Matt Oaxaca's user avatar
18 votes
1 answer
4k views

Is Open Data Protocol (odata) Being Widely Embraced by the Development Community? [closed]

EDIT: In case you aren't familiar with OData, here you go. I am trying to determine whether it is worth learning this technology or if it is something that is not going to catch on. The premise is ...
Matt Cashatt's user avatar
  • 3,305
17 votes
4 answers
27k views

Use composition and inheritance for DTOs

We have a ASP.NET Web API that provides a REST API for our Single Page Application. We use DTOs/POCOs to pass data through this API. The problem is now, that these DTOs are getting bigger over time, ...
officer's user avatar
  • 289
17 votes
3 answers
22k views

How to design a REST API to handle non-CRUD operations?

I'm trying to convert a set of SOAP-based services to a RESTful API. I started by identifying resources by analyzing operation names and I got the resource Subscription. When I need to update the ...
Vektor88's user avatar
  • 345
15 votes
1 answer
11k views

What is the point of link rel="self" in a REST API?

I often see the following in HTML documents <link rel="self" href="http://example.com/something"> or like this in JSON link: { rel="self", href="http://example.com/something" } ...
Laurent Bourgault-Roy's user avatar
13 votes
2 answers
14k views

Can a REST API return multiple resources as one single compound resource?

I'm in the progress of creating a REST API and currently, I'm encountering the following problem: Foo is the first resource. CRUD operations can be applied via the /foo/ URI. Bar is the second ...
ceran's user avatar
  • 255
13 votes
3 answers
7k views

Designing a REST API with resource relationships?

I'm working to design a REST API to be consumed by a React SPA. The client-side of the SPA queries data about a relationship between two entities: Team and Player where Teams have many Players and ...
Adam Thompson's user avatar
12 votes
5 answers
25k views

Is it a bad idea to pass JSON objects on the query string for an API "search" operation?

I'm building an API endpoint for a UI grid to search, filter, and display a list of domain objects, let's call them "widgets." In the past, I would have built this with a list of named query string ...
AJ Johnson's user avatar
12 votes
2 answers
24k views

How to avoid unauthorized use of an API?

I have to design a "widget", a script that partners will embed in their websites to display some UI and make calls to our API. Basically it will display our data on these sites based on some IDs they ...
Antoine's user avatar
  • 527
10 votes
1 answer
13k views

pattern to share objects between API and application

I'm having serious doubts about the design for my Web application. I wanted to separate the business logic from the interface so I made a Web API that handles all the requests to the database. It's ...
Marc's user avatar
  • 525
10 votes
3 answers
1k views

API endpoint POST vs GET

Help me settle an internal question. We have an endpoint which we all agree should be a GET, because all it's doing is calling a stored proc and returning a set of data. However, there is a set of ...
Casey Crookston's user avatar
10 votes
3 answers
2k views

REST API: Resource Ownership

Let's say there are Users and Pets. Each Pet has a single User as its owner, and a globally unique id. Endpoints could be /users/1/pets/2 /pets/2 I feel like the first option could be unintuitive ...
rtainc's user avatar
  • 105
8 votes
5 answers
563 views

How to map "mv" operation to HTTP verbs?

In designing a RESTful api the problem arises as to how best to allow resources to be moved between collections. Renaming a resource could be done by using PATCH but this is not the same thing as ...
Jon Guiton's user avatar
8 votes
5 answers
13k views

Is creating ViewModels in Web API a bad practice?

So, somebody at work who is twice as experienced than I am, told us that we must not create ViewModel classes within Web API. (We are using Angular for UI) In his opinion ViewModel is ASP.NET MVC ...
SamuraiJack's user avatar
8 votes
2 answers
2k views

How do you organize API endpoint contracts

Where trying to improve the "confidence" we have in our inter-service communication. Background: "Contracts" has been a matter of sharing a piece of code that defines an interface to implement, but ...
Julian's user avatar
  • 254
7 votes
2 answers
6k views

Best practice to handle POST with array of objects if at least one object raise an Exception

I want to POST an array of objects and make an insertion in database concerning each of them. What is the best practice if one object does not conform and raise an Exception? (cancel all transactions ...
Kénium's user avatar
  • 73
7 votes
3 answers
15k views

Should I use both WCF and ASP.NET Web API

We already have a WCF API with basichttpbinding. Some of the calls have complex objects in both the response and request. We need to add RESTful abilities to the API. at first I tried adding a ...
Mithir's user avatar
  • 1,329
7 votes
5 answers
357 views

How to designing API JSON Response with nullable fields

We were discussing how to design a API response, for simplicity, think of having to give information of all the different types of facilities available in a city: { "city": { "cityName": "...
daltonfury42's user avatar
7 votes
2 answers
19k views

How to correctly implement key=value storage REST API

I'm new to REST API, so I decided to get familiar with it by designing a small web service API. I have its design written down and would like you to review it. I feel like I have made some mistakes in ...
Waffle Lord's user avatar
7 votes
1 answer
5k views

How should data transfer between a client and a web API for normalized data be designed?

I want to design an API backed by some database (doesn't really matter which, but to make the discussion more interesting, let's say it's Mongo - explanation below) which sends data to a client. The ...
EyalAr's user avatar
  • 223
7 votes
1 answer
13k views

Return values for CRUD methods?

I'm writing a basic web API in Java that does what almost all others do: take input, validate it, then do CRUD operations on the DB. I've written several APIs before, and I've pretty much already ...
dsw88's user avatar
  • 1,859
7 votes
2 answers
3k views

Whether to embed linked resources in REST API

I am building a REST API where clients can query user-sent messages, like this: GET http://example.com/api/v1/messages?from=0&to=100 Response: [ { "id": 12345, "text": "...
Andrew Sun's user avatar
7 votes
2 answers
920 views

Separation of concerns and other best practices across Controllers, Services, Providers and Stores in ASP.NET when building a REST web api

I am traditionally a desktop app developer, but circumstance has thrust me into the role of doing web client and corresponding REST api logic for a project I am involved in. Unfortunately, I'm a one-...
Geo...'s user avatar
  • 171
7 votes
1 answer
7k views

Should the views or front-end server call the RESTful API layer

I need to build a new web application and I am looking for advice on how to manage communication to my API layer. My goal is to have complete separation between the front-end and back-end code. Like ...
sgmeyer's user avatar
  • 173
7 votes
2 answers
3k views

Authentication setup advice for web app and its backend API

I am fairly new to web development, and I am learning to build web applications. I am facing a problem figuring out how to set up authentication mechanisms for a multi-user application. Let me provide ...
Big Monday's user avatar
7 votes
1 answer
2k views

Handling events and incoming Web API calls simultaneously

I'm working on a project where I got an architecture with multiple "Microservices" communicating with each other by using an event bus (RabbitMQ). I got an Web API-project set up for each service so ...
CGeense's user avatar
  • 191
6 votes
2 answers
8k views

Good practice for status code returned by restful API when validating a token

I am working on client JavaScript SPA and a restful API on HTTPS. Client application needs to call a public endpoint (no token required) in order to valid (GET) a specific TOKEN previously remember ...
GibboK's user avatar
  • 705
6 votes
3 answers
1k views

GET vs POST when exposing machine learning model predictions using a REST API

So the recommendations for using GET vs POST in a REST API that I've read on stack overflow are geared almost exclusively toward CRUD operations involving a database. However if you are simply writing ...
erotavlas's user avatar
  • 267
6 votes
2 answers
5k views

What layer do third party API request/response models go in and what do you call them?

I have a RESTful API service that has three layers: Application/Domain, Infrastructure, and Presentation. Application/Domain contain my interfaces and models. I currently have three different types of ...
brandon d tran's user avatar
6 votes
2 answers
5k views

Is it bad practice to call another API from a Filter?

I am using Java, Spring and Jersey. I have a REST API A which receives a query parameter called q and sends this to another API B to get a response. I need to implement a change where I first need ...
Diyarbakir's user avatar
6 votes
1 answer
494 views

How does this kind of application and DDD relate?

In Domain-Driven Design the application is divided, as I understand, into four layers: Presentation Layer Application Layer Domain Layer Infrastructure Layer I understand this well, for instance, ...
user1620696's user avatar
  • 4,797
6 votes
1 answer
3k views

Token or ASP.NET Identity based security in ASP.NET Web API 2

Background I have a Web API 2 project, without any extension of ASP.NET MVC or ASP.NET projects. The API will only be used to communicate between the server and Windows 8, Windows Phone 8.1 and iOS ...
MikaelKP's user avatar
5 votes
2 answers
9k views

validation error responses in REST API

I'm designing a RESTful API and wondering what's the best format for validation error messages. For example, my account creation endpoint accepts a JSON object: user: { first_name: string, ...
sean hawk's user avatar
  • 159
5 votes
1 answer
8k views

why Web API 2 has RouteConfig.cs file?

I m working on Web API project, and it is using WebApiConfig.cs file to defined routs for Web API. Web API fold RouteConfig.cs file. I have googled and they say RouteConfig.cs is for MVC routing. It ...
user576510's user avatar

1
2 3 4 5
8