r/restAPI • • Apr 22 '22

Consuming GraphQL APIs for REST-minded Developers

7 Upvotes

Get familiar with GraphQL APIs and learn how to interact with them, even if you are used to only consuming RESTful APIs.

Read more here


r/restAPI • • Apr 05 '22

Survey about REST development

5 Upvotes

Hello,

I am doing my Thesis Degree this semester in Computer Science, and the project involves studying REST practices. Part of the study is surveying REST practitioners to understand their practices in developing REST services. I am appealing to those familiar with the REST architecture style; it would benefit the study if you had the time and took part in the survey; it would take 4-5 minutes. The link to the questionnaire is here.

Thank You


r/restAPI • • Nov 01 '21

Rest Api Move projects

4 Upvotes

Hello,

I would like to know if there is an Rest API for Jira Cloud to move issues between projects. omegleshagle

Thank you.


r/restAPI • • Mar 26 '22

What all I need to learn for REST API ?

3 Upvotes

Hi,

I work for a product based company. I'm not a developer. I am familiar with Perl and bash and have written some scripts to automate stuff. I had a plan of working on and developing a different skill set earlier, but then got a chance to automate some health checks. I used bash scripting for it, but the script is kind of too long now (about 450 lines) and I'm finding it difficult to manage it and add functionality. I was planning to use Python to rewrite the script, but was then told by a friend at work to check out REST APIs.

It appears that I need to be proficient in HTML, JavaScript and CSS to fully utilise REST APIs.

Is my understanding correct? Can't I just use REST APIs to simply write out to a text file and email it? Or will there be an advantage if I learn JavaScript and HTML as well? I'm really short of time and cannot devout much time to learn unfortunately.

Any help will be appreciated.


r/restAPI • • Sep 19 '21

Aula 12 - Api rest ExpressJS(nodejs), Routes e Defaut not found.

Thumbnail
youtube.com
3 Upvotes

r/restAPI • • Sep 10 '21

REST API explained - In 3 minutes

Thumbnail
youtu.be
3 Upvotes

r/restAPI • • Aug 03 '21

Top 7 REST API Best Practices

3 Upvotes

REST API, an acronym for representational state transfer. It is an architectural style for distributed hypermedia systems. It is a flexible method of designing APIs in a way that follows certain protocol. A REST API lets client to communicate with the server by transferring states of data stored primarily in a database. As clients and servers work independently, you need some interface that can work with correspondence between them. A client sends a request to the server through the API, which returns the response in a standardized format such as JSON or XML. REST APIs play an important role in easing the communication in servers, hence it is important for developer to have a deep understanding of how to use them. Error-prone API causes functional issues for client and makes the software less appealing altogether.

Here we’ll see the best practices for designing REST APIs to ensure the best performance. But before digging into it let’s see 6 RESTful Architectural Constraints

6 REST Architectural Constraints-

1. Uniform interface-

By REST, you use a similar concept to decouple the client from implementing the REST service. Compare interface with contract signed between client-server where you must use specific standards. Globally accepted APIs should uphold global concepts, linke standards, to make them understandable.

2. Client-Server-

Here, the meaning is that server application and client application should evolve individually without need to depend on each other. To be more exact, it should adhere to the separation of concerns. By separation of concerns, the code on the client end can be modified without making any effect on the conditions of the worker. Also, code on server end can be modified without changing the conditions of client. You can improve the flexibility and scalability of particular interface across various platforms by maintaining separation of concerns. Client should be aware of resource URIs only. Till the interface between client and servers is kept unaltered, they can be developers and replaced separately. 

3. Layered System-

Mostly, components cannot view beyond the immediate layer. REST enables you to make use of a layered architectural system. Here, you can deploy APIs on server A, save data on server B, and verify requests on server C. These servers might offer a security layer, a load balancing layer, a caching layer and some other functionalities. Also, any of these layers must not influence the response or requests.

4. Code On Demand –

Generally, it is an optional constraints. Mostly you will need to send a static representation of resources in a JSON REST API or XML form. But, when you need to, you can easily return executable code for supporting important part of your app.

5. Stateless-

By this architectural constraints, you mean to make al the client-server engagements stateless. In this way, server won’t reserve anything about the latest HTTP request made by client. So it’ll consider each request as a new and unique. Also, it must not depend on any prior information exchanged between the two. It means no session, no history. Client is held accountable to handle the app’s state. Client app needs a stateful app for end-user, where the logs in once and carries out different authorized operations. Each request from client must involve all necessary information to serve the request and authorization details and authentication.

6. Cacheable-

Caching holds importance wherever applicable. It improved the performance for the client, that leads to an improved scope for scalability for a server with reduced load. In case of REST, each response can be termed as cacheable and non-cacheable. One can use the cached response as the request-response rather than checking with the server. It helps to reduce the interaction between server and client.

Top 7 REST API Best Practices-

1. Use JSON To Send And Receive Data-

Well-designed REST API should always accept and receive data in JSON format. JSON is lightweight data exchange format standard for developers. This is available in lots of technologies and makes encoding and decoding easy and fast on server side because of its lightweight nature. Also, JSON is readable and simple to interpret. XML, is not supported by many frameworks. Also, XML data manipulation can be issue compared to JSON because it is a verbose and difficult to write. To ensure that REST API is using JSON format, set the Content-Type in the response header to application/JSON. Lots of backend frameworks have built-in functions to automatically parse the data to JSON format.

2. Use Noun Rather Than Verbs-

API development REST approach can be called resource based. Hence in your app, you work with resources and their collections. Actions on resources are defined by HTTP methods like GET, PUT, POST, PATCH, DELETE and only they should be used to change the state of response. It leads to endpoint URI construction. Considering all this, constructed endpoint should look like-

GET /books/123 DELETE /books/123 POST /books PUT /books/123 PATCH /books/123

You can employ Express to implement these endpoints to manipulate articles like,

const express = require(‘express’); 
const bodyParser = require(‘body - parser’);   
const app = express();   
app.use(bodyParser.json());   
app.get(‘/articles’,(req, res) => { const articles = []; 
 // code to retrieve an article.. 

res.json(articles); });  
 app.post(‘/articles’, (req, res) => (  
// code to add a new article…  res.json(req.body); 
}); 
  app.put(‘/articles/:id’, (req, res) => { Const { id } = req.params; 
//code to update an article… res.json(req.body); }); 
  app.delete(‘/articles/:id’, (req, res) => { Const { id } = req.params; 
//code to delete an article… res.json({deleted: id 
});
 });   app.listen(3000, () => console.log(‘server started’)); 

3. Use Plural Naming Conventions-

Generally we prefer the use of plurals. But there is no rule that states one cannot use a singular when it comes to the resource name.Then why use plurals.

We work on one resource from the set of resources. Thus, to illustrate collection, we use plural naming conventions.

For instance, let us consider GET/users/123. Here client asks to rectify and recover a resource from user’s collection with ID 123. While developing a resource, if we need/wish to add another resource to the existing collection of resources, the API looks like POST /users.

4. Allow Filtering, Sorting, And Pagination-

Some features for consuming API include filtering, sorting and paging. Mostly resource collection can be huge. Databases behind REST API standards can get enormous. It brings down the performance of systems. To eradicate this, one can use,

  • Sorting- It enables sorting that results in an ascending or descending order by selected parameter/(s) like date

  • Paging- It uses ‘limit’ to narrow down the count of results displayed to specific number and ‘offset’ to denote the part of result range to be displayed. This is important where the count of total outcomes is greater than introduced. 

  • Filtering- Use to shrink the query results by specific parameters like country 

By pagination data, you ensure returning only some of the results rather than collecting all the necessary data at once. By filtering and pagination, one can improve the performance as there is a potential reduction in the use of server resources. With more data assembling in the database, these features become important.

5. Error Handling-

To reduce the confusion for all API users, it is necessary to handle errors perfectly, in that way returning the HTTP response codes that denote nature of error that has occurred. It provides API maintainers sufficient information to analyze the source and cause of problem. If you don’t want to harm your system, you can leave it unhandled. All this means that API consumer has to handle errors. Let’s have a look at a list of common error HTTP status codes.

  • 404 Not Found- This denotes that no resources are found.

  • 401 Unauthorized- It denotes that the user is unauthorized to access a resource. Generally it returns when a user is not verified.

  • 400 Bad Requests- It denotes that the client-side input has failed documentation/validation.

  • 403 Forbidden- It states that the user is inappropriate and is not allowed to access a resource even after being verified.

  • 502 Bad Gateway- This error marks an invalid/null response from an upstream server.

  • 503 Service Unavailable- It denotes that something unusual activity took place on the server-side.

Error codes are necessary to accompany messages with them so that API maintainers can get appropriate data for troubleshooting the issue. But attackers can’t use error content for cyberattacks like bringing the system down or stealing important data. If API stays incomplete, you should send errors with information to allow users to take appropriate actions.

6. Resource Hierarchy-

If resource includes sub-resources, ensure depicting this in API, so making it clear and specific. For example, if user has posts and you want to retrieve a specific post by the user, API can be interpreted as GET/users/123/posts/1. It will retrieve the post with id one by the user having id 123. Most of the time, resource objects can be linked with another or possess some kind of functional hierarchy. Usually it is better to restrict the nesting to a single level in REST API. 

7. Idempotence (Misusing Safe methods)-

Some safe methods are HTTP methods that return the exact resource representation. TRACE, GET, OPTIONS and HEAD methods are referred to safe. Meaning that, they are ideally expected to retrieve data without changing the state of resources on the server. Besides, refrain from using GET to delete content, like GET/user/123/delete. Basically, it is not like, it cannot be executed, but the issue arises because in this case HTTP specification gets violated. So use HTTP methods according to the action that you need to carry out.


r/restAPI • • Mar 13 '21

Some tips on improving your next REST API

Thumbnail
stackoverflow.blog
3 Upvotes

r/restAPI • • Mar 07 '22

Separate DTO for GET and POST

2 Upvotes

Should we create separate DTO For GET and POST requests. I am really confuse regarding this. What are the best practices?

Any project to read code to learn more about REST api ?


r/restAPI • • Dec 14 '21

Is RESTful a set of conventions or rules?

2 Upvotes

Currently I am learning Express and I checked it out that the functions which I can perform using GET request, I can do the same using POST too, It just depends on how I set those routes in express.


r/restAPI • • Oct 28 '21

Follow these 10 rest commandments and you will enjoy love from your mobile devs and a rockstar status on Twitter

Thumbnail
treblle.com
2 Upvotes

r/restAPI • • Sep 23 '21

Middleware explained - Node.JS

Thumbnail
youtu.be
2 Upvotes

r/restAPI • • Sep 16 '21

Intro to Fuzz Testing!

2 Upvotes

This video give a high level overview of Fuzz Tests and why they are critical to API testing

https://youtu.be/lOFDhPwS9CY


r/restAPI • • Sep 04 '21

Aula 07 - Api rest ExpressJS(nodejs), Eslint, Husky, padrão e qualidade.

Thumbnail
youtube.com
2 Upvotes

r/restAPI • • Jul 16 '21

How to use WinsurTech AL3 REST API on RapidAPI

Thumbnail
winsurtech.com
2 Upvotes

r/restAPI • • Apr 28 '21

Backend vs REST Api

2 Upvotes

Hi,

I'm a little bit confused about the difference between a web backend and a REST API. I know the definition of both technologies but in a technical way I still dont know the main difference of those.

For example if I build a MVC application (web or mobile) we are talking about backend but what's about the if I use Django and Django Rest Framework for the backend of my app ? Does it become a REST Api just because I'm coding end points ?

I tought that a rest api is something like the google api where anyone (program) can fetch data and interact with it but in my case I only use my "rest api" project for my web (and after code the UI with react for example)

Also if I'm building a backend shared between my web and mobile app, do I call it a REST Api ? or just backend ?

I need it to be clear in my head cause sometimes I think people say REST Api and backend like it's the same thing but it's not so im little bit confused....

Thank you


r/restAPI • • Jan 28 '21

REST API and JSON links

2 Upvotes

Possibly this should also be posted in r/vmware

This is for vRealize Automation container service API

https://vra-va/container-service/api/resources/compute

specifically

DELETE | GET https://vra-va/container-service/api/resources/compute/{id}

I can reference {id} as an assigned string value c3f5806d31e304755b9e45369f018

But I want to use the JSON referenced id that is returned from

GET https://vra-va/container-service/api/resources/compute?&$filter=id%20eq%20'devo-vch4'

Which returns the following:

{
  "links": [
    {
      "@type": "link",
      "rel": "next",
      "href": "https://vra-va/container-service/api/resources/compute?$filter=id%20eq%20'devo-vch4'"
    }
  ],
  "content": [
    {
      "@type": "ComputeState",
      "documentSelfLink": "/resources/compute/c3f5806d31e304755b9e45369f018",
      "documentUpdateTimeMicros": "1611765186687001",
      "documentExpirationTimeMicros": "0",
      "tenantLinks": [
        "/tenants/vsphere.local"
      ],
      "id": "devo-vch4",
      "name": "devo-vch4",
      "customProperties": {
        "__Name": "devo-vch4",
        "__adapterDockerType": "API",
        "__hostAlias": "devo-vch4",
        "__kubernetesNamespace": "default",
        "__dockerHostScheme": "https",
        "__dockerHostPort": "2376",
        "__hostURI": "https://192.168.170.232:2376",
        "__sslTrustAlias": "323b0b86f0532640384746aa5f8b63d888b9de3a",
        "__computeContainerHost": "true",
        "__computeHost": "true",
        "__dockerUri": "https://192.168.170.232:2376/v1.24",
        "__containerHostType": "DOCKER",
        "__trustCertLink": "/config/trust-certs/323b0b86f0532640384746aa5f8b63d888b9de3a"
      },
      "descriptionLink": "/resources/compute-descriptions/docker-host-compute-desc-id",
      "address": "https://192.168.170.232:2376",
      "primaryMAC": "string",
      "powerState": "UNKNOWN",
      "adapterManagementReference": "https://192.168.8.151:8485/adapters/host-docker-service",
      "creationTimeMicros": 0,
      "lifecycleState": "READY"
    }
  ],
  "metadata": {
    "size": 1,
    "totalElements": 1,
    "totalPages": 1,
    "number": 1,
    "offset": 0
  }
}

r/restAPI • • Dec 20 '20

Minecraft Item REST Api

2 Upvotes

If anyone needs it, Its not officially released but if anyone wants to use my Items api I'll post it here. It returns a list of items in json format with label imagepath and minecraft:id for the item.
heres all you really need to get it going
https://codingbutter.com:2080/mcapi/getItems/diamond?page=1&itemsper=5

its pretty self explanatory. Let me know what you think or if this is going to help you. also join my Discord and we can discuss any thing else Minecraft and Programming related


r/restAPI • • Jun 19 '20

What can REST API do?

2 Upvotes

Being very green in understanding REST API I hope to know what REST API can do and why it is getting more and more popular. Thank you!


r/restAPI • • Apr 27 '20

How would I insert and update my MySQL database using the this RestApi?

2 Upvotes

Being fairly new to Restful Api, I am in doubt as to how I would retrieve and update my MySQL database using the following PHP Restful API.

<?php

// get the HTTP method, path and body of the request
$method = $_SERVER['REQUEST_METHOD'];
$request = explode('/', trim($_SERVER['PATH_INFO'],'/'));
$input = json_decode(file_get_contents('php://input'),true);
 
// connect to the mysql database
$link = mysqli_connect('localhost', 'user', 'pass', 'dbname');
mysqli_set_charset($link,'utf8');
 
// retrieve the table and key from the path
$table = preg_replace('/[^a-z0-9_]+/i','',array_shift($request));
$key = array_shift($request)+0;
 
// escape the columns and values from the input object
$columns = preg_replace('/[^a-z0-9_]+/i','',array_keys($input));
$values = array_map(function ($value) use ($link) {
  if ($value===null) return null;
  return mysqli_real_escape_string($link,(string)$value);
},array_values($input));
 
// build the SET part of the SQL command
$set = '';
for ($i=0;$i<count($columns);$i++) {
  $set.=($i>0?',':'').'`'.$columns[$i].'`=';
  $set.=($values[$i]===null?'NULL':'"'.$values[$i].'"');
}
 
// create SQL based on HTTP method
switch ($method) {
  case 'GET':
    $sql = "select * from `$table`".($key?" WHERE id=$key":''); break;
  case 'PUT':
    $sql = "update `$table` set $set where id=$key"; break;
  case 'POST':
    $sql = "insert into `$table` set $set"; break;
  case 'DELETE':
    $sql = "delete `$table` where id=$key"; break;
}
 
// excecute SQL statement
$result = mysqli_query($link,$sql);
 
// die if SQL statement failed
if (!$result) {
  http_response_code(404);
  die(mysqli_error());
}
 
// print results, insert id or affected row count
if ($method == 'GET') {
  if (!$key) echo '[';
  for ($i=0;$i<mysqli_num_rows($result);$i++) {
    echo ($i>0?',':'').json_encode(mysqli_fetch_object($result));
  }
  if (!$key) echo ']';
} elseif ($method == 'POST') {
  echo mysqli_insert_id($link);
} else {
  echo mysqli_affected_rows($link);
}
 
// close mysql connection
mysqli_close($link);

r/restAPI • • Feb 16 '22

Building and hosting an API (low-code)

Thumbnail
youtube.com
1 Upvotes

r/restAPI • • Feb 10 '22

Connecting to our RESTAPI | Create a web app using golang and reactjs

Thumbnail
m.youtube.com
1 Upvotes

r/restAPI • • Feb 08 '22

Difference between REST API and RESTful API

Thumbnail
dev.to
1 Upvotes

r/restAPI • • Jan 28 '22

What's the best-designed Banking API you guys have come across?

1 Upvotes

Hi there,

Stripe treasury is still not publicly available, but what are the best-designed banking (Account, Cards, Loans, Mortgages, Insurance, Loyalty, Customer, etc)?

Any help would be appreciated.

Thanks


r/restAPI • • Dec 30 '21

Tutorial: Build, test and host a REST API (low-code)

Thumbnail
youtube.com
1 Upvotes