Skip to main content
Developer

Building and Hosting REST APIs: What Your Server Needs

SSteboHost Team17 November 202617 min read20 views

Your mobile app, your website's checkout, your partner's inventory system and your M-Pesa payment confirmations all have something in common: they talk to a server through an API. When that API is slow, insecure or offline, everything built on top of it breaks, however good the app looks.

Building a REST API is the easy part. Hosting it properly is where many projects stumble. An API has different needs from a brochure website: it handles many small requests, needs fast responses, must protect tokens and data, and often has to stay available around the clock.

This guide explains what a REST API needs from its server, from runtime and database to HTTPS, security, caching and monitoring, and how to choose the type of hosting that fits your project and traffic.

Key takeaways

  • A REST API serves data to apps and other systems over HTTP, usually as JSON. Its hosting needs are driven by response time, concurrency and security more than by page design.

  • Always serve an API over HTTPS. Tokens and customer data travel in every request.

  • Match the hosting to the runtime. PHP APIs can run on web hosting, while Node.js, Python and other long-running app servers generally need developer-oriented hosting or a VPS.

  • Concurrency, database performance and caching usually decide how fast your API feels, not raw bandwidth.

  • Build in authentication, rate limiting, input validation and logging from the start, and put a firewall in front.

  • Monitor uptime, latency and error rates, and keep tested backups. An API outage is felt immediately by every client that depends on it.

What Is a REST API (and What Does It Ask of a Server)?

A REST API is a way for software to request and change data on a server using standard web methods. A client sends an HTTP request to an address (an endpoint), and the server returns a response, usually in JSON. For example:

  • GET /v1/products returns a list of products

  • POST /v1/orders creates a new order

  • PUT or PATCH /v1/orders/123 updates an order

  • DELETE /v1/orders/123 removes an order

REST APIs are typically stateless, which means each request carries everything the server needs, such as an authentication token, instead of relying on a stored session. That makes them easy to scale, but it also means every request has to be authenticated, validated and answered quickly.

From a hosting point of view, that translates into a specific set of demands:

  • Many short requests, often arriving at the same time

  • Low and predictable response times

  • A database that can keep up

  • Secure connections and strong access control

  • High availability, because other software depends on it

  • A way to deploy changes without breaking existing clients

What Your Server Needs: A Checklist

Requirement

Why it matters

The right runtime and versions

Your code needs the language, framework and extensions it was built for, at supported versions

Enough CPU and memory for concurrent requests

Each request uses processing time. Too little capacity means queues, timeouts and errors

A reliable database

Most API time is spent waiting for queries

HTTPS with a valid certificate

Protects tokens and data in transit. Required by most clients and webhooks

A way to run your app continuously

Node.js, Python and similar apps need a process manager, not just a folder of files

Fast storage and sensible limits

Logs, uploads, queues and caches all use disk and file operations

Caching

Lets you answer repeated requests without rebuilding the response

Security controls

Firewall, rate limiting, validation and secrets management

Logging and monitoring

You cannot fix what you cannot see

Backups and a recovery plan

Protects data and gets you back online after mistakes

A deployment workflow

Safe releases, staging and quick rollbacks

Good network placement

Latency to your users adds to every request

Runtime: Match Your Code to the Hosting

Different languages are served in different ways, and this is the single biggest factor in choosing hosting.

Stack

How it usually runs

Typical hosting fit

PHP (Laravel, Slim, Symfony, plain PHP)

PHP is started per request by the web server (PHP-FPM or LiteSpeed's PHP handler)

Web hosting with cPanel, developer hosting or a VPS

Node.js (Express, Fastify, NestJS)

A long-running process behind a web server

Developer hosting that supports Node.js apps, or a VPS

Python (FastAPI, Django, Flask)

An application server such as Gunicorn or Uvicorn behind a web server

Developer hosting that supports Python apps, or a VPS

Go, Rust, Java and .NET

A compiled service listening on a port

A VPS or dedicated server

Containerised services

Docker images run by a container runtime

A VPS or dedicated server

Two practical points:

  • Run supported versions. Old runtime versions stop receiving security fixes. If you use PHP, our guide to PHP versions and website speed explains why the version matters for both speed and security.

  • Match production to development. Use the same major versions of the runtime and database on your laptop, in staging and in production, to avoid surprises.

A simple routing setup for PHP APIs

On Apache-compatible hosting, including LiteSpeed, a PHP API usually sends every request that is not a real file to a single entry file, which then routes it. In .htaccess:

RewriteEngine On
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^ index.php [L]

Other frameworks have their own recommended web server configuration, so check their deployment documentation.

CPU, Memory and Concurrency

An API's speed under load depends on how many requests it can handle at once. Ask three questions:

  • How many requests per second do you expect at normal times and at peaks, such as a promotion or the end of the month?

  • How long does a typical request take to process, including database queries and calls to other services?

  • How many workers or processes can run at once on your hosting?

If a request takes 100 milliseconds and you can run four at once, you can handle roughly 40 requests per second in the best case. Slow requests reduce that number quickly, and a few slow external calls can block all your workers. That is why shared hosting plans publish limits on concurrent processes, and why busy APIs often move to a VPS with dedicated CPU and RAM. See our guide to reading your cPanel resource usage for how those limits show up on shared hosting.

A practical way to find your limits is a load test. Tools such as k6, wrk, Apache Bench or Locust send many requests to your API and show how response times change as load rises. Test on a staging copy, never on a production system that real customers rely on.

The Database Behind the API

Most API latency is database latency. To keep it low:

  • Choose the right database for the job. MySQL or MariaDB and PostgreSQL suit most business APIs.

  • Add indexes for the columns you filter and sort by, and check slow queries.

  • Avoid N+1 queries, where one request triggers hundreds of small queries. Load related data in bulk instead.

  • Paginate list endpoints so one call never returns thousands of rows.

  • Mind connection limits. Every worker may hold a database connection, and databases only allow so many.

  • Use a dedicated database user for the API, with only the permissions it needs.

  • Keep the database close to the application, ideally on the same server or network, to avoid extra latency.

  • Back it up and practise restoring.

If the same data is read again and again, cache it (see below) instead of asking the database each time.

HTTPS Is Not Optional

Every API request carries something sensitive: an access token, an API key or customer data. Without HTTPS, anyone on the network path can read or alter them.

  • Serve the API only over HTTPS, and redirect or refuse plain HTTP.

  • Use a valid certificate that covers your API address, for example api.yourcompany.co.ke. SteboHost hosting plans include automatic SSL certificates, and current plan terms are on the pricing page.

  • Use modern TLS versions (TLS 1.2 or 1.3) and consider the HSTS header once everything works over HTTPS.

  • Remember that webhooks and payment callbacks usually require a public HTTPS address. Safaricom's Daraja callbacks for M-Pesa, for instance, need a valid secure URL to deliver payment results.

Our guide to setting up SSL and forcing HTTPS covers redirects and common problems in detail.

Your API Address and DNS

A common pattern is to run the API on its own subdomain, such as api.yourcompany.co.ke, separate from your website. Create an A record (or CNAME) for it in your DNS, point it at the server running the API, and get a certificate for that name. A separate address also lets you move the API to another server later without changing your website. See managed DNS for managing the records, and our guide to pointing a domain to your hosting for the steps.

Security: Protect the Data and the Endpoints

APIs are attractive targets because they expose data in a predictable, machine-readable way.

Authentication and authorisation

  • Use proven methods: API keys for simple server-to-server use, and OAuth 2.0 or short-lived signed tokens (such as JWTs) for apps and users.

  • Check authorisation on every request, so a valid user cannot read or change another user's data by guessing an ID.

  • Keep access tokens short-lived, and support revocation.

  • Never put secrets in client-side code, mobile apps or Git repositories.

Input validation and safe database access

  • Validate every field's type, length and format on the server, and never trust the client.

  • Use parameterised queries or your framework's query builder to prevent SQL injection.

  • Limit request body sizes and file upload types.

Rate limiting and abuse protection

  • Limit how many requests one client can make in a given time, and return a 429 Too Many Requests status with a clear message.

  • Add stricter limits to login, password reset and other sensitive endpoints.

  • Put a web application firewall and DDoS protection in front of the API. SteboHost includes a WAF, Imunify360 malware scanning and DDoS mitigation on every plan. See website security.

At the web server level, Nginx can apply a simple rate limit. This example allows about 10 requests per second per client address, with a short burst, for requests under /v1/:

limit_req_zone $binary_remote_addr zone=api:10m rate=10r/s;

server {
  listen 443 ssl;
  server_name api.example.com;

  location /v1/ {
    limit_req zone=api burst=20 nodelay;
    proxy_pass http://127.0.0.1:8000;
    proxy_set_header Host $host;
    proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
    proxy_set_header X-Forwarded-Proto $scheme;
  }
}

The limit_req_zone line belongs in the http block of your Nginx configuration, and the server block also needs your certificate settings.

CORS and security headers

If browsers call your API from another site, configure CORS so that only the origins you trust are allowed, and never use a wildcard for APIs that handle private data. Add standard security headers, and make sure error responses never leak stack traces, file paths or database details.

Secrets and configuration

Keep passwords, tokens and keys in environment variables or a secrets store, never in your code repository. Use different values for development, staging and production, and rotate any secret that may have been exposed.

Personal data

If your API handles customers' personal data, Kenya's Data Protection Act applies to it. Collect only what you need, encrypt data in transit, restrict access, avoid writing personal data into logs and have a breach response plan. Our guide to the Data Protection Act explains the main duties for website and API owners.

Design Choices That Make Hosting Easier

  • Version your API (for example /v1/) so you can improve it without breaking existing apps.

  • Use consistent status codes: 200 and 201 for success, 400 for bad input, 401 and 403 for authentication and permission problems, 404 for missing resources, 429 for rate limiting and 5xx for server problems.

  • Return structured errors, for example using the Problem Details format (RFC 9457), so clients can handle failures properly.

  • Paginate and filter list endpoints.

  • Make writes idempotent where possible, so a retried payment or order request does not create duplicates. Idempotency keys are a common technique.

  • Add a health endpoint such as /health that checks the app and its database, so monitors and load balancers can see when something is wrong.

  • Keep responses small: return only the fields clients need, and compress responses.

A health check can be as simple as:

GET /health

200 OK
{"status":"ok","database":"ok"}

Caching and Performance

The fastest request is the one your server does not have to compute again.

  • HTTP caching: send Cache-Control and ETag headers on responses that rarely change, so clients and intermediaries can reuse them.

  • Application caching: store expensive results in memory with a cache such as Redis, or in your framework's cache, and expire them sensibly.

  • Compression: enable gzip or Brotli for JSON responses.

  • Keep-alive and HTTP/2: reuse connections instead of reconnecting for every request. Both work over HTTPS.

  • Move slow work out of the request: send emails, generate reports and process uploads in background jobs, and return a quick response.

  • Respond quickly to webhooks: acknowledge receipt immediately with a 2xx status, and do the heavy processing afterwards. Many providers retry when a callback times out.

  • Place the server near your users. Latency adds to every request, which matters for mobile apps used across East Africa. Our guide to hosting location and website speed explains why.

Deployment: Releasing Changes Safely

  • Use Git for your code, with a repeatable build and deployment process, ideally automated by a CI pipeline.

  • Test changes on staging before production, using a copy of your environment. See our guide to staging environments.

  • Keep configuration outside the code, in environment variables, so the same build runs everywhere.

  • Release without downtime: start the new version, check its health endpoint, then switch traffic or reload the process.

  • Keep a rollback plan: the previous build or a tagged release, plus a database backup before schema changes.

  • Run database migrations carefully, and make them backward compatible, so old and new versions of the app can both work during a release.

  • Keep a process manager such as systemd or PM2 (for Node.js) in charge of your app so it restarts after crashes and reboots.

Monitoring, Logging and Backups

  • Uptime monitoring: check a public endpoint, such as /health, every minute or so from outside your network, and alert the right people when it fails. SteboHost's monitoring watches uptime, resources and security events, and you can follow incidents on the system status page.

  • Metrics: track request rate, response time (including the slowest requests, not just the average), error rate and resource use.

  • Logs: log requests and errors with a request ID so you can trace problems, but never log passwords, tokens or full personal data.

  • Alerts with context: alert on symptoms, such as rising error rates, not only on a server being down.

  • Backups: back up databases and uploaded files, store a copy away from the main server, and test restoring. See backup and disaster recovery.

Choosing the Right Hosting for Your API

Hosting type

Good for

Watch out for

Web hosting (shared, cPanel)

Small PHP-based APIs, internal tools, low to moderate traffic

Published limits on concurrent processes and resources. Not suited to long-running processes

Developer Hosting

Developer-focused projects. Check the plan page for supported runtimes, deployment options and limits

Confirm that your runtime and process model are supported

VPS and cloud hosting

Node.js, Python, containers, background workers and anything needing full control

You manage the server, updates and security

Dedicated servers

High and steady load, strict performance or isolation needs

More capacity than small projects need

A sensible path for many projects is to start small, measure real usage and move up when the data tells you to. When you outgrow one level, SteboHost's product pages describe the upgrade options.

Common Mistakes to Avoid

  • Serving an API over HTTP, or mixing HTTP and HTTPS

  • Putting secrets in code or in a public repository

  • No rate limiting, so one noisy client slows everyone down

  • Checking who the user is, but not what they are allowed to access

  • Slow database queries with no indexes

  • Doing slow work inside the request instead of in a background job

  • Returning detailed errors and stack traces to clients

  • No health checks, monitoring or alerts

  • Deploying straight to production with no staging and no rollback plan

  • Breaking clients by changing responses without versioning

  • Ignoring backups until the day they are needed

Why Host Your API With SteboHost

SteboHost gives developers a clear path from a first API to a production system:

  • A choice of foundations. Run PHP APIs on SteboHost web hosting with LiteSpeed and NVMe storage, see Developer Hosting for developer-focused options, or use VPS and cloud hosting with dedicated CPU and RAM, full root access, Ubuntu, Debian and AlmaLinux images and snapshot backups.

  • Security on every plan. A web application firewall, Imunify360 malware scanning and DDoS mitigation, plus 24/7 infrastructure monitoring.

  • Automatic SSL certificates included with hosting plans, using Let's Encrypt and renewed automatically. Current plan terms are on the pricing page.

  • Daily backups on shared hosting plans, with 7-day retention and one-click restore.

  • Published resource limits on every plan page, so you can plan capacity. See the plan limits.

  • A 99.9% uptime SLA and a public system status page.

  • Migration help on annual plans. Terms are shown on the pricing page and at checkout.

  • Local support on +254 703 610 464 during East Africa Time business hours, with 24/7 urgent monitoring, and billing in KES by M-Pesa, card or bank transfer.

Current plan and renewal prices are shown on the pricing page before you buy. You can also browse the knowledge base for more developer guides.

Conclusion

A good API host is not about one big feature. It is the combination of the right runtime, enough capacity for concurrent requests, a fast database, HTTPS everywhere, layered security, sensible caching, careful deployments and monitoring you trust. Start with your language and your expected load, choose hosting that fits, test it under pressure and keep improving as real usage teaches you more.

Planning an API project and not sure which hosting fits? Contact the team or call +254 703 610 464, and SteboHost will help you choose between web hosting, Developer Hosting and a VPS.

Frequently Asked Questions

What does a REST API need from its hosting server?

It needs the right runtime and versions for your code, enough CPU and memory to handle concurrent requests, a reliable and well-indexed database, HTTPS with a valid certificate, a way to run the app continuously, caching, security controls such as a firewall and rate limiting, monitoring and logging, backups and a safe deployment process.

Can I host a REST API on shared web hosting?

Often yes, if it is a PHP-based API and the traffic is small to moderate. PHP runs per request on shared hosting, so it fits well. Node.js, Python and other long-running app servers usually need developer-oriented hosting that supports them, or a VPS. Check the plan limits for concurrent processes and resources.

Do I need a VPS to host a Node.js or Python API?

Not always, because some developer-focused hosting plans support Node.js or Python applications. A VPS is the right choice when you need full control, such as a specific runtime version, background workers, Docker, a database on the same server or a custom web server configuration.

Is HTTPS required for a REST API?

Yes, for any real project. Every request carries tokens or data that should not travel in plain text, many clients and webhook providers refuse non-HTTPS addresses, and browsers block insecure calls from secure pages. Use a valid certificate that covers your API address.

How do I protect my API from abuse?

Authenticate every request, check permissions on every resource, validate all input, apply rate limits (returning 429 when exceeded), use a web application firewall and DDoS protection, keep secrets out of code, log suspicious activity and monitor error rates. No single measure is enough, so layer them.

How do I know how much server capacity my API needs?

Estimate your normal and peak requests per second, measure how long a typical request takes, and run a load test on a staging copy with a tool such as k6, wrk or Locust. Watch CPU, memory, database performance and error rates as load rises, and size your hosting for the peak with some headroom.

Should my API have its own subdomain?

It is a good idea. A subdomain such as api.yourcompany.co.ke keeps the API separate from your website, lets you give it its own certificate and server, and makes it easier to move or scale later without changing your main site.

#REST API#API Hosting#Developer Hosting#Node.js#PHP#Security#Performance#VPS
S

Written by SteboHost Team

SteboHost engineering and operations team. We write practical guides on hosting, domains, email and security for African businesses — based on what we see in the field, not marketing copy.

Ready to get started?

Browse our hosting plans or contact our team for help choosing the right one.