Git Product home page Git Product logo

murphy's Introduction

Murphy

Build Status GoDoc

An opinionated view on JSON APIs, and a short implementation in Golang.

tl;dr

type Request struct { Name string }

type Response struct { Greeting string }

func Hello(ctx *murphy.HttpContext, req *Request, resp *Response) error {
	if len(req.Name) == 0 {
		return murphy.BadRequestErrorf("name missing")
	}
	resp.Greeting = "Hello " + req.Name
	return nil
}

and installed as such

http.Handle("/hello", murphy.JsonHandler(Hello))
log.Fatal(http.ListenAndServe(":8080", nil))

Remote APIs

At the simplest level, remote APIs such as "JSON APIs" can be looked at through the lens of normal API design. The domain the API deals with has its concepts, lexicon, short and long lived entities, and operations to create, mutate, discover / list, or otherwise destroy these.

Where things depart from simple API design is the remotness. This introduces two complexities: transport, and error handling.

From the client's perspective (i.e. the caller), invoking a remote method results in one of two states: unknown where you do not know whether things succeeded or failed; and known where you either know things succeeded, or know they failed. The former typically occurs with timeout, network separation, or any other I/O level problem; the latter is a property of the API being invoked. Dealing with unknown state is fun, and such a large topic by itself that we're goind to elude it here. Dealing with known state is almost similar as API design... you got it, error handling.

murphy's People

Contributors

pascallouisperez avatar cbelsole avatar workmajj avatar alexandrinaw avatar

Watchers

Mike Abner avatar Joe Mocerino avatar James Cloos avatar Pratik Prasad avatar  avatar Aimee Monko avatar Jane Wallace avatar  avatar

murphy's Issues

Can the HttpContext interface

... instead, simply use a struct with 3 values. Wrote this back in the day when I was learning Go and was all giddy 'bout interfaces. Makes testing harder, for no good reason.

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.