Desktop Applications
Desktop applications can be a viable option in certain scenarios (so long as the people you are targeting use desktops and laptops, such as if you are creating an app to be used in a work environment).
Native apps usually offer the most interactive and enjoyable experience, so they are a great option when the application must be extremely responsive. Programs that involve drawing and a variety of games must be able to respond quickly to the user’s input. Picture yourself beginning to sketch a line or fire at a hostile creature when out of the blue there’s a short pause. That may not appear to be an extended period of time, however in the midst of an activity, it can destroy the experience for the individual.
A disadvantage to a desktop application is that a person must download and set it up before they can utilize it, unlike a web application which can be used straight from their web browser. Desktop applications are not the most suitable option for programs that people need to access right away. In certain situations, the individual won’t be able to get your app and put it in their device. Large corporations often prohibit users from making many alterations to their computers. This is an instance when you need to be aware of who you are speaking to.
How to Create a Desktop App
So you’ve decided to create a desktop app. Great. What operating system do you intend to back? Is the app going to be compatible with Windows, Mac, or Linux?
Every one of these operating systems has its own distinct commands for doing things like creating, opening, and saving documents, printing, downloading and uploading data over a network or the web, assembling pictures, and more. These instructions are known as Application Programming Interfaces, commonly referred to as APIs. Each platform has thousands of these. Although it’s not necessary to become familiar with them all, the distinct commands for each platform can be challenging to master if you plan on providing support for more than a single platform.
The tools required for creating the user interface of your app will vary depending on the platform it is being designed for, as each platform vendor supplies their own development tools.
On Windows, it’s Microsoft Visual Studio . On MacOS, it’s Xcode . Eclipse is one of the most favored choices for Linux, though there are a variety of others available.
It can be advantageous to work with multiple platforms, yet it can be time-consuming for the developer to manage even one. Supporting multiple platforms can only amplify the issue. The positive outcome is that creating applications across multiple platforms significantly decreases the amount of time required. More on that in a bit.
Build the backend
Add functionality for API requests
The initial necessity for the application is to be able to dispatch GET and POST requests to the GitHub API. Make a new file in the main folder of the program, which should be called api.go. In this file, add the following code.
package main
import (
"bytes"
"fmt"
"io"
"net/http"
)
func makeRequest(requestType, url, token string, payload []byte ) ([]byte, error){
client := &http.Client{}
var request *http.Request
if payload != nil {
requestBody := bytes.NewReader(payload)
request, _ = http.NewRequest(requestType, url, requestBody)
} else {
request, _ = http.NewRequest(requestType, url, nil)
}
request.Header.Set("Accept", "application/vnd.github+json")
if token != "" {
request.Header.Set("Authorization", fmt.Sprintf("Bearer %s", token))
}
response, err := client.Do(request)
if err != nil {
return nil, fmt.Errorf("request failed: %w", err)
}
body, _ := io.ReadAll(response.Body)
return body, nil
}
func MakeGetRequest(url string, token string) ([]byte, error) {
return makeRequest("GET", url, token, nil)
}
func MakePostRequest(url, token string, payload []byte) ([]byte, error){
return makeRequest("POST", url, token, payload)
}
The internal workings of the system employ the makeRequest() function in order to send a query to a given URL. Besides denoting the URL, the function gets passed the request type, token, and information to be sent. These can be employed to create the request and then transmit it with the answer from the API that the function gave.
The makeRequest() function is used as the basis for the MakeGetRequest() and MakePostRequest() functions, which are specialized for sending GET and POST requests respectively.
Bind helper functions to the app
You can utilize the API functionality by creating some helper functions which will be connected to the frontend. This involves incorporating receiver functions for the App structure.
At the conclusion of app.go, there is a Greet() receiver function that serves as an illustration of this concept.
func (a *App) Greet(name string) string {
return fmt.Sprintf("Hello %s, It's show time!", name)
}
Now, add the following code to app.go .
type APIResponse []interface{}
type Gist struct {
Description string `json:"description"`
Public bool `json:"public"`
Files interface{} `json:"files"`
}
const BaseUrl = "https://api.github.com"
var githubResponse APIResponse
func (a *App) GetPublicRepositories() (APIResponse, error) {
url := fmt.Sprintf("%s/repositories", BaseUrl)
response, err := MakeGetRequest(url, "")
if err != nil {
return nil, err
}
json.Unmarshal(response, &githubResponse)
return githubResponse, nil
}
func (a *App) GetPublicGists() (APIResponse, error) {
url := fmt.Sprintf("%s/gists/public", BaseUrl)
response, err := MakeGetRequest(url, "")
if err != nil {
return nil, err
}
json.Unmarshal(response, &githubResponse)
return githubResponse, nil
}
func (a *App) GetRepositoriesForAuthenticatedUser(token string) (APIResponse, error) {
url := fmt.Sprintf("%s/user/repos?type=private", BaseUrl)
response, err := MakeGetRequest(url, token)
if err != nil {
return nil, err
}
json.Unmarshal(response, &githubResponse)
return githubResponse, nil
}
func (a *App) GetGistsForAuthenticatedUser(token string) (APIResponse, error) {
url := fmt.Sprintf("%s/gists", BaseUrl)
response, err := MakeGetRequest(url, token)
if err != nil {
return nil, err
}
json.Unmarshal(response, &githubResponse)
return githubResponse, nil
}
func (a *App) GetMoreInformationFromURL(url, token string) (APIResponse, error) {
response, err := MakeGetRequest(url, token)
if err != nil {
return nil, err
}
json.Unmarshal(response, &githubResponse)
return githubResponse, nil
}
func (a *App) GetGistContent(url, token string) (string, error) {
githubResponse, err := MakeGetRequest(url, token)
if err != nil {
return "", err
}
return string(githubResponse), nil
}
func (a *App) CreateNewGist(gist Gist, token string) (interface{}, error) {
var githubResponse interface{}
requestBody, _ := json.Marshal(gist)
url := fmt.Sprintf("%s/gists", BaseUrl)
response, err := MakePostRequest(url, token, requestBody)
if err != nil {
return nil, err
}
json.Unmarshal(response, &githubResponse)
return githubResponse, nil
}
If you are using a text editor or IDE, make sure to include “encoding/json” in the list of imports at the beginning of the file; if your text editor or IDE doesn’t add it in automatically, you will have to do it yourself.
As well as the current code, it creates two new kinds: APIResponse and Gist. These will be employed to simulate a reaction from the API and the design of a Gist respectively. Next, it declares the receiver functions for the App struct:
- The
GetPublicRepositories()
function retrieves a list of public repositories from the GitHub API via a GET request. Since this route does not require authentication, an empty string is passed as the token. - The
GetPublicGists()
function retrieves a list of public Gists from the GitHub API via a GET request. Authentication is also not required, hence an empty string is passed as the token. - The
GetRepositoriesForAuthenticatedUser()
function is used to get a list of the authenticated user’s private repositories. This function takes the token as a parameter. - The
GetGistsForAuthenticatedUser()
function is used to retrieve the authenticated user’s Gists. This function also takes a token as a parameter. - The
GetMoreInformationFromURL()
function is used to get more information on a repository. This information could be the commit history, list of contributors, or list of users who have starred the repository. It takes two parameters, the url to be called and the authentication token. For public repositories, the token will be an empty string. - The
GetGistContent()
function is used to get the content of a Gist. This function takes the URL for the Gist’s raw content and an authentication token (an empty string for public Gists). It returns a string corresponding to the content of the Gist. - The
CreateNewGist()
function is used to create a new Gist for the authenticated user. This function takes two parameters, the Gist to be created as well as the authentication token for the user.
Web Applications
Web applications enable you to circumvent the drawbacks of desktop applications, as they let people access and use them right away instead of having to go through the downloading and setup process first. Web applications are advantageous since they are simple for the programmer to alter. Put a fresh edition of your application on the web server and your job is done – it is now accessible to all users immediately.
The drawback of designing web applications is that making them run extremely quickly can be hard to impossible, particularly if the app will depend on data from the server. Due to the lack of control you have over the Internet, the speed can be inconsistent, changing from hour to hour or day to day based on the state of the Internet.
Worry about safety is an issue because the application only runs on the server. If the server’s safety is breached, it has an effect on all users. Protecting a web server is a complex task that requires a specialized set of skills and knowledge.
How to Create a Web App
Creating web applications has numerous advantages, but they are not simple to create. A web app is really two apps. One application operates in the web browser of the user, while the other operates on a server. You program both components so that they work together and appear as one application to the user. Having two applications running on different computers typically requires knowledge of five different technologies. The client (browser) side utilizes HTML, JavaScript, and CSS, while AJAX and PHP are used on the server side.
I’ve only encountered a handful of individuals that are familiar with all of these technologies. It is unusual to come across an individual who is familiar with all web applications even in consulting firms that specialize in creating them. Generally, there are individuals who are knowledgeable about the customer aspect and others who are familiar with the server aspect. When it comes to the interaction between the apps, both teams must cooperate even though they are each working on their own parts. Without a doubt, constructing a web application with the customary tools can be a substantial task.
Mobile Applications
If the user requires access to your app anytime, anywhere, a mobile app is likely the best choice. Mobile applications are beneficial as they are hosted directly on the customer’s device, allowing them to be speedy and reactive. Obtaining and setting up applications for Android and iOS devices is effortless, though users still need to download and install them.
It is simple for both you as a developer and your users to refresh mobile applications. Submit a fresh iteration of the app to the app store and your users will be informed that it is now available. A single tap installs the update for them. It is necessary that a certain amount of work be done on your end in order to make it as effortless as possible for the user.
The disadvantage of using mobile applications is that the size of the display on the average smartphone is quite limited. Phones that are larger in size (often referred to as phablets) still don’t have displays that are as big as a laptop, and a lot of people do not want to tote a tablet around with them. It is difficult to make a user interface that is as complex as the one made for desktop computers. The most important factor in deciding to create a mobile app is the complexity of the user interface and how widely available the application is.
Mobile applications that give the current information of something (like a business data dashboard) are very useful. Typically, you don’t require much room on the display and they usually don’t require a lot of interaction. Nevertheless, designing an app that permits the user to examine the components that form those metrics could be quite difficult to fit onto a smartphone display.
How to Create a Mobile App
Desktop and web applications are generally employed on a standard computer display where a great deal of area is accessible, so the user interface you design for those two can often be comparable. It’s not the same situation with mobile applications that have to be compatible with a display that is one fifth the size of a laptop’s. Mobile apps usually feature multiple full-screen displays that the user goes through as they utilize the app.
Mobile technology has its own distinct operating systems with their own individual tools, application programming interfaces, and programming languages. As an illustration, Google offers Android Studio as a development utility, the Android Operating System has a complete set of Application Programming Interfaces, and you write your programming in Java. For iOS, Apple offers XCode as a development environment, employs CocoaTouch as its application programming interface, and utilizes either Swift or Objective-C as its programming language.
Leave a Reply