Given that an API in web apps is the interface and contract between the front end and backend, it’s useful to know which side is violating that contract when things go wrong. Given cURL’s widespread installation base, you can build scripts for testing and deployment dependent on cURL without worry of being locked into a single vendor. cURL is included in most *nix distributions which makes it a handy tool for anyone SSHing into remote hosts without worrying about installing custom tools. If you prefer command line based tools, cURL Postman even includes some nice touches such as auto completing standard HTTP headers and supporting and rendering a variety of payloads from JSON, to HTML, to even multipart. A history of past calls is stored so you can quickly reissue it. It has a very beautiful GUI interface and very easy to use regardless if your just starting out with RESTful APIs or an expert. One of the most popular HTTP clients is Postman.
In addition, browsers have tight security policies that prevent changing things like the Origin header Putting the URL directly in the browser, but browsers can get in the way via local caching so you really don’t know what’s Sure, you could just fire off a GET request by Whether your a mobile app developer testing requests against a back end or developing and running your own service. Most web developers will need to send API requests at one point or another. This post organizes the various tools by its use case. While this post focuses on development,Įxpect a followup post on the best tools for delivering reliable APIs in production. Often while developing and working with APIs. We thought we’d share some of the best ones we really liked and use Our own API to “eat your own dog food”, but we also use many other tools, many of them free.
Of course, we use our own API analytics on Some of these are internal APIs powering our various services, while others are externalĪPIs such as our payments provider or authentication service.īoth from internal and third-party sources. In this tutorial, we will implement all REST methods in a new controller.As we developed the Moesif API analytics platform, we needed to create and use many APIs.
posts) via the GET model parameter.įor the Get Single Item and Update Item method, we will receive the model's primary key via the GET id parameter. Note that for all requests, we will get the requested model (e.g. In order to parse these URL's, set up the URL manager in config/main.php like this. Delete a post: index.php/api/posts/123 ( DELETE).Update a post: index.php/api/posts/123 ( PUT).Create a new post: index.php/api/posts ( POST).View a single posts: index.php/api/posts/123 (also GET ).View all posts: index.php/api/posts (HTTP method GET).When using the API, we would like to have the following URL scheme: comments or user data.Īll requests to the API shall use an authorization.Īll right, let's get things going! Setting up the URL Manager ¶ The API shall be flexible enough that it can be extended easily to work on more different models, e.g. Speaking of a model here means the Post model, i.e. In this tutorial, we will use the Yii Blog demo application. Get one single model item via its primary key (id).If you want to send REST requests via a console, perhaps you might check cUrl. To fire up a REST request to a Yii application, you can use the Firefox REST Client Addon. Information about REST ¶Ī good introduction about implementing REST service with PHP can be found on.
This article will explain how to create a REST API with the Yii framework.