DEV Community

Cover image for Top 8 Leading API Architectural Styles Across the Tech Industry (Part 1)
Emmanuel Ayinde
Emmanuel Ayinde

Posted on β€’ Edited on

6 1 1 1 1

Top 8 Leading API Architectural Styles Across the Tech Industry (Part 1)

In this post, I will delve into the prominent API architectural styles within the realm of programming that are worthy of discussion today, with some common implementation in Python and JavaScript.

First of all, What is an API?

API (Application Programming Interface) architectural styles define the way in which different components of software systems communicate and interact with each other.
There are several architectural styles for designing APIs, and here are eight major ones:

1. Remote Procedure Call (RPC):

RPC involves invoking procedures or functions on a remote server as if they were local. It abstracts the network communication and provides a way for clients to call methods on remote services. Examples of RPC APIs include gRPC and XML-RPC.

// server.js

const { GreeterClient } = require('./rpc_example_pb_grpc.js');
const { HelloRequest } = require('./rpc_example_pb.js');

const client = new GreeterClient('http://localhost:8080');

const request = new HelloRequest();
request.setName('John');

client.sayHello(request, {}, (error, response) => {
    if (!error) {
        console.log('Greeting:', response.getMessage());
    }
}); 

Enter fullscreen mode Exit fullscreen mode

2. Representational State Transfer (REST):

REST is a widely and commonly used architectural style that is based on a set of constraints to build scalable and maintainable APIs. RESTful APIs use HTTP methods (GET, POST, PUT / PATCH, DELETE) to perform CRUD operations on resources represented by URLs. They rely on stateless communication and use standard status codes for response interpretation.

// server.js

const express = require('express');
const app = express();

app.get('/hello', (req, res) => {
    res.json({ message: 'Hello, World!' });
});

app.listen(3000, () => {
    console.log('Server is running on port 3000');
});

Enter fullscreen mode Exit fullscreen mode

3. Simple Object Access Protocol (SOAP):

SOAP is a protocol that uses XML for communication between services. It focuses on the structure of the messages and includes a set of standards for various aspects of communication like security and transactions. SOAP APIs can be more complex to work with compared to REST.

// server.js

const axios = require('axios');

const requestData = `
    <soapenv:Envelope xmlns:soapenv="http://schemas.xmlsoap.org/soap/envelope/" xmlns:web="http://www.example.com/webservice">
        <soapenv:Header/>
        <soapenv:Body>
            <web:MethodName>
                <web:param1>value1</web:param1>
                <web:param2>value2</web:param2>
            </web:MethodName>
        </soapenv:Body>
    </soapenv:Envelope>
`;

axios.post('http://www.example.com/webservice', requestData, {
    headers: { 'Content-Type': 'text/xml' }
})
.then(response => {
    console.log(response.data);
})
.catch(error => {
    console.error(error);
});

Enter fullscreen mode Exit fullscreen mode

4. Graph Query Language (GraphQL):

GraphQL is a query language and runtime for APIs that allows clients to request exactly the data they need. Unlike REST, where the server dictates the shape of the response, GraphQL clients specify the structure of the response. This can reduce over-fetching and under-fetching of data.

// server.js 

const express = require('express');
const { graphqlHTTP } = require('express-graphql');
const { GraphQLSchema, GraphQLObjectType, GraphQLString } = require('graphql');

const app = express();

const QueryType = new GraphQLObjectType({
  name: 'Query',
  fields: {
    hello: {
      type: GraphQLString,
      resolve: () => 'Hello, world!'
    }
  }
});

const schema = new GraphQLSchema({
  query: QueryType
});

app.use('/graphql', graphqlHTTP({
  schema: schema,
  graphiql: true,
}));

app.listen(3000, () => {
  console.log('GraphQL server is running on port 3000');
});

Enter fullscreen mode Exit fullscreen mode

Each of these architectural styles has its own strengths and weaknesses, and the choice of style depends on factors such as the nature of the application, the communication requirements, and the development team's familiarity with the technology. This is just part of the architectural styles, others will be explained and discussed soon. Don't miss it.

You can continue to the second part of the article Here πŸ”₯πŸ”₯πŸ”₯


Connect with me πŸ”₯πŸ”₯

GitHub
Twitter
LinkedIn

Till the next post, Stay tuned and happy coding 😍

Hostinger image

Get n8n VPS hosting 3x cheaper than a cloud solution

Get fast, easy, secure n8n VPS hosting from $4.99/mo at Hostinger. Automate any workflow using a pre-installed n8n application and no-code customization.

Start now

Top comments (1)

Collapse
 
emmanuelayinde profile image
Emmanuel Ayinde β€’

Follow me for more update on #programming #softwaredevelopment. Part 2 of this is coming soon πŸ”₯ πŸ”₯

A Workflow Copilot. Tailored to You.

Pieces.app image

Our desktop app, with its intelligent copilot, streamlines coding by generating snippets, extracting code from screenshots, and accelerating problem-solving.

Read the docs

πŸ‘‹ Kindness is contagious

Explore a trove of insights in this engaging article, celebrated within our welcoming DEV Community. Developers from every background are invited to join and enhance our shared wisdom.

A genuine "thank you" can truly uplift someone’s day. Feel free to express your gratitude in the comments below!

On DEV, our collective exchange of knowledge lightens the road ahead and strengthens our community bonds. Found something valuable here? A small thank you to the author can make a big difference.

Okay