Dataford
Popular roles
Software EngineerData AnalystData ScientistData EngineerBusiness AnalystAI EngineerMachine Learning EngineerProduct Manager
Browse
Browse All RolesEvery role hub, from analyst to MLBrowse All CompaniesCompany-specific interview loopsAll Interview GuidesThe full guide library
Top questions by role
Software EngineerData AnalystData ScientistData EngineerBusiness AnalystAI EngineerMachine Learning EngineerProduct Manager
Top questions by skill
SQLPythonStatisticsMachine LearningA/B TestingSystem DesignGenerative AIProduct SenseMetricsBehavioral
Browse all questions →Try a mock interview
ExperiencesCoaching
New
Practice
Mock InterviewsTimed interview simulations with feedbackSuccess PathYour 6-week structured planModulesCurated lessons by topicWebinarsTalks from ex-Big Tech data leadsPlaygroundA free-form scratch editor
Learn
BlogInterview strategy and career adviceTech Job Market ReportHiring trends across data and AI rolesFor UniversitiesDataford for career centersAbout DatafordWho we are and how we build
Pricing
Get started
Define REST API
00:00
5 left

Define REST API

MediumSQL · PostgreSQL

Problem

What is a REST API?

For this SQL exercise, analyze recorded REST API requests. Write a query that summarizes successful requests for each endpoint.

Output

  1. One row per endpoint with columns endpoint, successful_request_count, and avg_response_time_ms
  2. Include only requests with status codes from 200 through 299; rows with a NULL status code are ignored
  3. Exclude NULL response times from the average, while still counting successful requests
  4. Order by successful request count descending, then endpoint ascending

Schema

api_requests
ColumnTypeDescription
request_idPKINTUnique request identifier
endpointVARCHAR(100)REST API endpoint that received the request
http_methodVARCHAR(30)HTTP method used by the request
status_codeINTHTTP response status code
response_time_msNUMERIC(10,2)Response time in milliseconds
requested_atTIMESTAMPTimestamp when the request was received
Tablesapi_requests
Interviewer

Whenever you're ready, walk me through your approach or go straight to the code. The requirements and the one table are in the Question tab.

You need to log in / sign up to run or submit.
CodePostgreSQL
Sign up free to run your codeLog inLn 1
Run your query to see results here.